feat: include AdditionalClaims in /oauth2/userinfo response (#834)
Signed-off-by: afsu <suaf2020@163.com>
This commit is contained in:
parent
a3f2a52fea
commit
230de6253a
|
|
@ -721,15 +721,17 @@ func (p *OAuthProxy) UserInfo(rw http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
userInfo := struct {
|
||||
User string `json:"user"`
|
||||
Email string `json:"email"`
|
||||
Groups []string `json:"groups,omitempty"`
|
||||
PreferredUsername string `json:"preferredUsername,omitempty"`
|
||||
User string `json:"user"`
|
||||
Email string `json:"email"`
|
||||
Groups []string `json:"groups,omitempty"`
|
||||
PreferredUsername string `json:"preferredUsername,omitempty"`
|
||||
AdditionalClaims map[string]interface{} `json:"additionalClaims,omitempty"`
|
||||
}{
|
||||
User: session.User,
|
||||
Email: session.Email,
|
||||
Groups: session.Groups,
|
||||
PreferredUsername: session.PreferredUsername,
|
||||
AdditionalClaims: session.AdditionalClaims,
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(rw).Encode(userInfo); err != nil {
|
||||
|
|
|
|||
|
|
@ -1032,6 +1032,20 @@ func TestUserInfoEndpointAccepted(t *testing.T) {
|
|||
},
|
||||
expectedResponse: "{\"user\":\"john.doe\",\"email\":\"john.doe@example.com\",\"groups\":[\"example\",\"groups\"],\"preferredUsername\":\"john\"}\n",
|
||||
},
|
||||
{
|
||||
name: "With Additional Claim",
|
||||
session: &sessions.SessionState{
|
||||
User: "john.doe",
|
||||
PreferredUsername: "john",
|
||||
Email: "john.doe@example.com",
|
||||
Groups: []string{"example", "groups"},
|
||||
AccessToken: "my_access_token",
|
||||
AdditionalClaims: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
expectedResponse: "{\"user\":\"john.doe\",\"email\":\"john.doe@example.com\",\"groups\":[\"example\",\"groups\"],\"preferredUsername\":\"john\",\"additionalClaims\":{\"foo\":\"bar\"}}\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
Loading…
Reference in New Issue