Add User & Groups to Userinfo
This commit is contained in:
		
							parent
							
								
									3ff0c23a9e
								
							
						
					
					
						commit
						2549b722d3
					
				|  | @ -55,6 +55,7 @@ | ||||||
| - [#797](https://github.com/oauth2-proxy/oauth2-proxy/pull/797) Create universal Authorization behavior across providers (@NickMeves) | - [#797](https://github.com/oauth2-proxy/oauth2-proxy/pull/797) Create universal Authorization behavior across providers (@NickMeves) | ||||||
| - [#898](https://github.com/oauth2-proxy/oauth2-proxy/pull/898) Migrate documentation to Docusaurus (@JoelSpeed) | - [#898](https://github.com/oauth2-proxy/oauth2-proxy/pull/898) Migrate documentation to Docusaurus (@JoelSpeed) | ||||||
| - [#754](https://github.com/oauth2-proxy/oauth2-proxy/pull/754) Azure token refresh (@codablock) | - [#754](https://github.com/oauth2-proxy/oauth2-proxy/pull/754) Azure token refresh (@codablock) | ||||||
|  | - [#850](https://github.com/oauth2-proxy/oauth2-proxy/pull/850) Increase session fields in `/oauth2/userinfo` endpoint (@NickMeves) | ||||||
| - [#825](https://github.com/oauth2-proxy/oauth2-proxy/pull/825) Fix code coverage reporting on GitHub actions(@JoelSpeed) | - [#825](https://github.com/oauth2-proxy/oauth2-proxy/pull/825) Fix code coverage reporting on GitHub actions(@JoelSpeed) | ||||||
| - [#796](https://github.com/oauth2-proxy/oauth2-proxy/pull/796) Deprecate GetUserName & GetEmailAdress for EnrichSessionState (@NickMeves) | - [#796](https://github.com/oauth2-proxy/oauth2-proxy/pull/796) Deprecate GetUserName & GetEmailAdress for EnrichSessionState (@NickMeves) | ||||||
| - [#705](https://github.com/oauth2-proxy/oauth2-proxy/pull/705) Add generic Header injectors for upstream request and response headers (@JoelSpeed) | - [#705](https://github.com/oauth2-proxy/oauth2-proxy/pull/705) Add generic Header injectors for upstream request and response headers (@JoelSpeed) | ||||||
|  |  | ||||||
|  | @ -798,13 +798,19 @@ func (p *OAuthProxy) UserInfo(rw http.ResponseWriter, req *http.Request) { | ||||||
| 		http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) | 		http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	userInfo := struct { | 	userInfo := struct { | ||||||
| 		Email             string `json:"email"` | 		User              string   `json:"user"` | ||||||
| 		PreferredUsername string `json:"preferredUsername,omitempty"` | 		Email             string   `json:"email"` | ||||||
|  | 		Groups            []string `json:"groups,omitempty"` | ||||||
|  | 		PreferredUsername string   `json:"preferredUsername,omitempty"` | ||||||
| 	}{ | 	}{ | ||||||
|  | 		User:              session.User, | ||||||
| 		Email:             session.Email, | 		Email:             session.Email, | ||||||
|  | 		Groups:            session.Groups, | ||||||
| 		PreferredUsername: session.PreferredUsername, | 		PreferredUsername: session.PreferredUsername, | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	rw.Header().Set("Content-Type", "application/json") | 	rw.Header().Set("Content-Type", "application/json") | ||||||
| 	rw.WriteHeader(http.StatusOK) | 	rw.WriteHeader(http.StatusOK) | ||||||
| 	err = json.NewEncoder(rw).Encode(userInfo) | 	err = json.NewEncoder(rw).Encode(userInfo) | ||||||
|  |  | ||||||
|  | @ -1130,14 +1130,18 @@ func TestUserInfoEndpointAccepted(t *testing.T) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	startSession := &sessions.SessionState{ | 	startSession := &sessions.SessionState{ | ||||||
| 		Email: "john.doe@example.com", AccessToken: "my_access_token"} | 		User:        "john.doe", | ||||||
|  | 		Email:       "john.doe@example.com", | ||||||
|  | 		Groups:      []string{"example", "groups"}, | ||||||
|  | 		AccessToken: "my_access_token", | ||||||
|  | 	} | ||||||
| 	err = test.SaveSession(startSession) | 	err = test.SaveSession(startSession) | ||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
| 
 | 
 | ||||||
| 	test.proxy.ServeHTTP(test.rw, test.req) | 	test.proxy.ServeHTTP(test.rw, test.req) | ||||||
| 	assert.Equal(t, http.StatusOK, test.rw.Code) | 	assert.Equal(t, http.StatusOK, test.rw.Code) | ||||||
| 	bodyBytes, _ := ioutil.ReadAll(test.rw.Body) | 	bodyBytes, _ := ioutil.ReadAll(test.rw.Body) | ||||||
| 	assert.Equal(t, "{\"email\":\"john.doe@example.com\"}\n", string(bodyBytes)) | 	assert.Equal(t, "{\"user\":\"john.doe\",\"email\":\"john.doe@example.com\",\"groups\":[\"example\",\"groups\"]}\n", string(bodyBytes)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestUserInfoEndpointUnauthorizedOnNoCookieSetError(t *testing.T) { | func TestUserInfoEndpointUnauthorizedOnNoCookieSetError(t *testing.T) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue