return "oauth2_grant"
}
-// GenerateNewAuthorizationCode generates a new authorization code for a grant and saves it to the databse
+// GenerateNewAuthorizationCode generates a new authorization code for a grant and saves it to the database
func (grant *OAuth2Grant) GenerateNewAuthorizationCode(redirectURI, codeChallenge, codeChallengeMethod string) (*OAuth2AuthorizationCode, error) {
return grant.generateNewAuthorizationCode(x, redirectURI, codeChallenge, codeChallengeMethod)
}
type OIDCToken struct {
jwt.StandardClaims
Nonce string `json:"nonce,omitempty"`
+
+ // Scope profile
+ Name string `json:"name,omitempty"`
+ PreferredUsername string `json:"preferred_username,omitempty"`
+ Profile string `json:"profile,omitempty"`
+ Picture string `json:"picture,omitempty"`
+ Website string `json:"website,omitempty"`
+ Locale string `json:"locale,omitempty"`
+ UpdatedAt timeutil.TimeStamp `json:"updated_at,omitempty"`
+
+ // Scope email
+ Email string `json:"email,omitempty"`
+ EmailVerified bool `json:"email_verified,omitempty"`
}
// SignToken signs an id_token with the (symmetric) client secret key
ErrorDescription: "cannot find application",
}
}
+ err = app.LoadUser()
+ if err != nil {
+ if models.IsErrUserNotExist(err) {
+ return nil, &AccessTokenError{
+ ErrorCode: AccessTokenErrorCodeInvalidRequest,
+ ErrorDescription: "cannot find user",
+ }
+ }
+ log.Error("Error loading user: %v", err)
+ return nil, &AccessTokenError{
+ ErrorCode: AccessTokenErrorCodeInvalidRequest,
+ ErrorDescription: "server error",
+ }
+ }
+
idToken := &models.OIDCToken{
StandardClaims: jwt.StandardClaims{
ExpiresAt: expirationDate.AsTime().Unix(),
},
Nonce: grant.Nonce,
}
+ if grant.ScopeContains("profile") {
+ idToken.Name = app.User.FullName
+ idToken.PreferredUsername = app.User.Name
+ idToken.Profile = app.User.HTMLURL()
+ idToken.Picture = app.User.AvatarLink()
+ idToken.Website = app.User.Website
+ idToken.Locale = app.User.Language
+ idToken.UpdatedAt = app.User.UpdatedUnix
+ }
+ if grant.ScopeContains("email") {
+ idToken.Email = app.User.Email
+ idToken.EmailVerified = app.User.IsActive
+ }
+
signedIDToken, err = idToken.SignToken(clientSecret)
if err != nil {
return nil, &AccessTokenError{