Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type discoveryOIDC struct {
UserInfo string `json:"userinfo_endpoint"`
DeviceEndpoint string `json:"device_authorization_endpoint"`
Introspect string `json:"introspection_endpoint"`
Registration string `json:"registration_endpoint,omitempty"`
GrantTypes []string `json:"grant_types_supported"`
ResponseTypes []string `json:"response_types_supported"`
Subjects []string `json:"subject_types_supported"`
Expand All @@ -96,6 +97,7 @@ type discoveryOAuth2 struct {
Keys string `json:"jwks_uri"`
DeviceEndpoint string `json:"device_authorization_endpoint,omitempty"`
Introspect string `json:"introspection_endpoint,omitempty"`
Registration string `json:"registration_endpoint,omitempty"`
GrantTypes []string `json:"grant_types_supported"`
ResponseTypes []string `json:"response_types_supported"`
CodeChallengeAlgs []string `json:"code_challenge_methods_supported,omitempty"`
Expand All @@ -116,7 +118,7 @@ func (s *Server) discoveryHandler(ctx context.Context, t DiscoveryType) (http.Ha
switch t {
case DiscoveryOAuth2:
d = s.constructDiscoveryOAuth2()
default:
case DiscoveryOIDC:
d = s.constructDiscoveryOIDC(ctx)
}

Expand All @@ -141,6 +143,7 @@ func (s *Server) constructDiscoveryOIDC(ctx context.Context) discoveryOIDC {
UserInfo: s.absURL("/userinfo"),
DeviceEndpoint: s.absURL("/device/code"),
Introspect: s.absURL("/token/introspect"),
Registration: s.absURL("/register"),
Subjects: []string{"public"},
IDTokenAlgs: []string{string(jose.RS256)},
CodeChallengeAlgs: []string{codeChallengeMethodS256, codeChallengeMethodPlain},
Expand Down Expand Up @@ -177,6 +180,7 @@ func (s *Server) constructDiscoveryOAuth2() discoveryOAuth2 {
Keys: s.absURL("/keys"),
DeviceEndpoint: s.absURL("/device/code"),
Introspect: s.absURL("/token/introspect"),
Registration: s.absURL("/register"),
CodeChallengeAlgs: []string{codeChallengeMethodS256, codeChallengeMethodPlain},
Scopes: []string{"offline_access"},
AuthMethods: []string{"client_secret_basic", "client_secret_post"},
Expand Down
86 changes: 44 additions & 42 deletions server/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestHandleDiscoveryOIDC(t *testing.T) {
UserInfo: fmt.Sprintf("%s/userinfo", httpServer.URL),
DeviceEndpoint: fmt.Sprintf("%s/device/code", httpServer.URL),
Introspect: fmt.Sprintf("%s/token/introspect", httpServer.URL),
Registration: fmt.Sprintf("%s/register", httpServer.URL),
GrantTypes: []string{
"authorization_code",
"refresh_token",
Expand Down Expand Up @@ -107,48 +108,49 @@ func TestHandleDiscoveryOIDC(t *testing.T) {
}

func TestHandleDiscoveryOAuth2(t *testing.T) {
httpServer, server := newTestServer(t, nil)
defer httpServer.Close()

rr := httptest.NewRecorder()
server.ServeHTTP(rr, httptest.NewRequest("GET", "/.well-known/oauth-authorization-server", nil))

if rr.Code != http.StatusOK {
t.Errorf("expected 200 got %d", rr.Code)
}

var res discoveryOAuth2
err := json.NewDecoder(rr.Result().Body).Decode(&res)
require.NoError(t, err)

require.Equal(t, discoveryOAuth2{
Issuer: httpServer.URL,
Auth: fmt.Sprintf("%s/auth", httpServer.URL),
Token: fmt.Sprintf("%s/token", httpServer.URL),
Keys: fmt.Sprintf("%s/keys", httpServer.URL),
DeviceEndpoint: fmt.Sprintf("%s/device/code", httpServer.URL),
Introspect: fmt.Sprintf("%s/token/introspect", httpServer.URL),
GrantTypes: []string{
"authorization_code",
"refresh_token",
"urn:ietf:params:oauth:grant-type:device_code",
"urn:ietf:params:oauth:grant-type:token-exchange",
},
ResponseTypes: []string{
"code",
},
CodeChallengeAlgs: []string{
"S256",
"plain",
},
Scopes: []string{
"offline_access",
},
AuthMethods: []string{
"client_secret_basic",
"client_secret_post",
},
}, res)
httpServer, server := newTestServer(t, nil)
defer httpServer.Close()

rr := httptest.NewRecorder()
server.ServeHTTP(rr, httptest.NewRequest("GET", "/.well-known/oauth-authorization-server", nil))

if rr.Code != http.StatusOK {
t.Errorf("expected 200 got %d", rr.Code)
}

var res discoveryOAuth2
err := json.NewDecoder(rr.Result().Body).Decode(&res)
require.NoError(t, err)

require.Equal(t, discoveryOAuth2{
Issuer: httpServer.URL,
Auth: fmt.Sprintf("%s/auth", httpServer.URL),
Token: fmt.Sprintf("%s/token", httpServer.URL),
Keys: fmt.Sprintf("%s/keys", httpServer.URL),
DeviceEndpoint: fmt.Sprintf("%s/device/code", httpServer.URL),
Introspect: fmt.Sprintf("%s/token/introspect", httpServer.URL),
Registration: fmt.Sprintf("%s/register", httpServer.URL),
GrantTypes: []string{
"authorization_code",
"refresh_token",
"urn:ietf:params:oauth:grant-type:device_code",
"urn:ietf:params:oauth:grant-type:token-exchange",
},
ResponseTypes: []string{
"code",
},
CodeChallengeAlgs: []string{
"S256",
"plain",
},
Scopes: []string{
"offline_access",
},
AuthMethods: []string{
"client_secret_basic",
"client_secret_post",
},
}, res)
}

func TestHandleHealthFailure(t *testing.T) {
Expand Down
Loading