mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-12-27 18:42:30 +00:00
feat: forward sub from oidc providers
This commit is contained in:
@@ -213,6 +213,7 @@ func (auth *AuthService) CreateSessionCookie(c *gin.Context, data *config.Sessio
|
||||
OAuthGroups: data.OAuthGroups,
|
||||
Expiry: time.Now().Add(time.Duration(expiry) * time.Second).Unix(),
|
||||
OAuthName: data.OAuthName,
|
||||
OAuthSub: data.OAuthSub,
|
||||
}
|
||||
|
||||
err = gorm.G[model.Session](auth.database).Create(c, &session)
|
||||
@@ -314,6 +315,7 @@ func (auth *AuthService) GetSessionCookie(c *gin.Context) (config.SessionCookie,
|
||||
TotpPending: session.TOTPPending,
|
||||
OAuthGroups: session.OAuthGroups,
|
||||
OAuthName: session.OAuthName,
|
||||
OAuthSub: session.OAuthSub,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -173,6 +173,9 @@ func (github *GithubOAuthService) Userinfo() (config.Claims, error) {
|
||||
user.PreferredUsername = userInfo.Login
|
||||
user.Name = userInfo.Name
|
||||
|
||||
// Github does not implement OIDC, so no sub is available
|
||||
user.Sub = "not_available_dont_use_me"
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ var GoogleOAuthScopes = []string{"https://www.googleapis.com/auth/userinfo.email
|
||||
type GoogleUserInfoResponse struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type GoogleOAuthService struct {
|
||||
@@ -117,6 +118,9 @@ func (google *GoogleOAuthService) Userinfo() (config.Claims, error) {
|
||||
user.Name = userInfo.Name
|
||||
user.Email = userInfo.Email
|
||||
|
||||
// We can use the id as the sub
|
||||
user.Sub = userInfo.Id
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user