git.iko.soy/typeable/oauth2-proxy
on master help sign in
Add User & Groups to Userinfo
commit2549b722d3044762438c9c2995bdb16d17954c95 authorNick Meves <nick.meves@greenhouse.io> dateSun 18 Oct 2020, 18:57 (6 years ago) parent3ff0c23
3 files changed+15−4
CHANGELOG.md+1 oauthproxy.go+8−2 oauthproxy_test.go+6−2
CHANGELOG.md+1
@@ -55,6 +55,7 @@
5555- [#797](https://github.com/oauth2-proxy/oauth2-proxy/pull/797) Create universal Authorization behavior across providers (@NickMeves)
5656- [#898](https://github.com/oauth2-proxy/oauth2-proxy/pull/898) Migrate documentation to Docusaurus (@JoelSpeed)
5757- [#754](https://github.com/oauth2-proxy/oauth2-proxy/pull/754) Azure token refresh (@codablock)
58+- [#850](https://github.com/oauth2-proxy/oauth2-proxy/pull/850) Increase session fields in `/oauth2/userinfo` endpoint (@NickMeves)
5859- [#825](https://github.com/oauth2-proxy/oauth2-proxy/pull/825) Fix code coverage reporting on GitHub actions(@JoelSpeed)
5960- [#796](https://github.com/oauth2-proxy/oauth2-proxy/pull/796) Deprecate GetUserName & GetEmailAdress for EnrichSessionState (@NickMeves)
6061- [#705](https://github.com/oauth2-proxy/oauth2-proxy/pull/705) Add generic Header injectors for upstream request and response headers (@JoelSpeed)
oauthproxy.go+8−2
@@ -798,13 +798,19 @@ func (p *OAuthProxy) UserInfo(rw http.ResponseWriter, req *http.Request) {
798798 http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
799799 return
800800 }
801+
801802 userInfo := struct {
802− Email string `json:"email"`
803− PreferredUsername string `json:"preferredUsername,omitempty"`
803+ User string `json:"user"`
804+ Email string `json:"email"`
805+ Groups []string `json:"groups,omitempty"`
806+ PreferredUsername string `json:"preferredUsername,omitempty"`
804807 }{
808+ User: session.User,
805809 Email: session.Email,
810+ Groups: session.Groups,
806811 PreferredUsername: session.PreferredUsername,
807812 }
813+
808814 rw.Header().Set("Content-Type", "application/json")
809815 rw.WriteHeader(http.StatusOK)
810816 err = json.NewEncoder(rw).Encode(userInfo)
oauthproxy_test.go+6−2
@@ -1130,14 +1130,18 @@ func TestUserInfoEndpointAccepted(t *testing.T) {
11301130 }
11311131
11321132 startSession := &sessions.SessionState{
1133− Email: "john.doe@example.com", AccessToken: "my_access_token"}
1133+ User: "john.doe",
1134+ Email: "john.doe@example.com",
1135+ Groups: []string{"example", "groups"},
1136+ AccessToken: "my_access_token",
1137+ }
11341138 err = test.SaveSession(startSession)
11351139 assert.NoError(t, err)
11361140
11371141 test.proxy.ServeHTTP(test.rw, test.req)
11381142 assert.Equal(t, http.StatusOK, test.rw.Code)
11391143 bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
1140− assert.Equal(t, "{\"email\":\"john.doe@example.com\"}\n", string(bodyBytes))
1144+ assert.Equal(t, "{\"user\":\"john.doe\",\"email\":\"john.doe@example.com\",\"groups\":[\"example\",\"groups\"]}\n", string(bodyBytes))
11411145}
11421146
11431147func TestUserInfoEndpointUnauthorizedOnNoCookieSetError(t *testing.T) {