Skip to content

Commit 3cd99fe

Browse files
committed
fix: open id config
1 parent 2bd92d6 commit 3cd99fe

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

server/constants/oauth2.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ const (
1414
ResponseTypeCode = "code"
1515
// For the Implicit grant, use response_type=token to include an access token.
1616
ResponseTypeToken = "token"
17+
// For the Implicit grant of id_token, use response_type=id_token to include an identifier token.
18+
ResponseTypeIDToken = "id_token"
1719
)

server/handlers/authorize.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,34 @@ func AuthorizeHandler() gin.HandlerFunc {
137137

138138
// in case, response type is code and user is already logged in send the code and state
139139
// and cookie session will already be rolled over and set
140-
gc.HTML(http.StatusOK, authorizeWebMessageTemplate, gin.H{
141-
"target_origin": redirectURI,
142-
"authorization_response": map[string]interface{}{
143-
"type": "authorization_response",
144-
"response": map[string]string{
145-
"code": code,
146-
"state": state,
140+
if responseMode == constants.ResponseModeFormPost {
141+
gc.HTML(http.StatusOK, authorizeFormPostTemplate, gin.H{
142+
"target_origin": redirectURI,
143+
"authorization_response": map[string]interface{}{
144+
"type": "authorization_response",
145+
"response": map[string]string{
146+
"code": code,
147+
"state": state,
148+
},
147149
},
148-
},
149-
})
150+
})
151+
} else {
152+
gc.HTML(http.StatusOK, authorizeWebMessageTemplate, gin.H{
153+
"target_origin": redirectURI,
154+
"authorization_response": map[string]interface{}{
155+
"type": "authorization_response",
156+
"response": map[string]string{
157+
"code": code,
158+
"state": state,
159+
},
160+
},
161+
})
162+
}
163+
150164
return
151165
}
152166

153-
if responseType == constants.ResponseTypeToken {
167+
if responseType == constants.ResponseTypeToken || responseType == constants.ResponseTypeIDToken {
154168
// rollover the session for security
155169
authToken, err := token.CreateAuthToken(gc, user, claims.Roles, scope, claims.LoginMethod)
156170
if err != nil {
@@ -222,7 +236,7 @@ func AuthorizeHandler() gin.HandlerFunc {
222236
}
223237

224238
func validateAuthorizeRequest(responseType, responseMode, clientID, state, codeChallenge string) error {
225-
if responseType != constants.ResponseTypeCode && responseType != constants.ResponseTypeToken {
239+
if responseType != constants.ResponseTypeCode && responseType != constants.ResponseTypeToken && responseType != constants.ResponseTypeIDToken {
226240
return fmt.Errorf("invalid response type %s. 'code' & 'token' are valid response_type", responseMode)
227241
}
228242

server/handlers/openid_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func OpenIDConfigurationHandler() gin.HandlerFunc {
2222
"jwks_uri": issuer + "/.well-known/jwks.json",
2323
"response_types_supported": []string{"code", "token", "id_token", "code token", "code id_token", "token id_token", "code token id_token"},
2424
"scopes_supported": []string{"openid", "email", "profile", "email_verified", "given_name", "family_name", "nick_name", "picture"},
25-
"response_modes_supported": []string{"query", "fragment", "form_post"},
25+
"response_modes_supported": []string{"query", "fragment", "form_post", "web_message"},
2626
"id_token_signing_alg_values_supported": []string{jwtType},
2727
"claims_supported": []string{"aud", "exp", "iss", "iat", "sub", "given_name", "family_name", "middle_name", "nickname", "preferred_username", "picture", "email", "email_verified", "roles", "gender", "birthdate", "phone_number", "phone_number_verified"},
2828
})

0 commit comments

Comments
 (0)