@@ -72,7 +72,7 @@ func (s *Server) handlePublicKeys(w http.ResponseWriter, r *http.Request) {
7272 w .Write (data )
7373}
7474
75- type discovery struct {
75+ type discoveryOIDC struct {
7676 Issuer string `json:"issuer"`
7777 Auth string `json:"authorization_endpoint"`
7878 Token string `json:"token_endpoint"`
@@ -90,8 +90,36 @@ type discovery struct {
9090 Claims []string `json:"claims_supported"`
9191}
9292
93- func (s * Server ) discoveryHandler () (http.HandlerFunc , error ) {
94- d := s .constructDiscovery ()
93+ type discoveryOAuth2 struct {
94+ Issuer string `json:"issuer"`
95+ Auth string `json:"authorization_endpoint"`
96+ Token string `json:"token_endpoint"`
97+ Keys string `json:"jwks_uri"`
98+ DeviceEndpoint string `json:"device_authorization_endpoint,omitempty"`
99+ Introspect string `json:"introspection_endpoint,omitempty"`
100+ GrantTypes []string `json:"grant_types_supported"`
101+ ResponseTypes []string `json:"response_types_supported"`
102+ CodeChallengeAlgs []string `json:"code_challenge_methods_supported,omitempty"`
103+ Scopes []string `json:"scopes_supported,omitempty"`
104+ AuthMethods []string `json:"token_endpoint_auth_methods_supported,omitempty"`
105+ }
106+
107+ type DiscoveryType int
108+
109+ const (
110+ DiscoveryOIDC DiscoveryType = iota
111+ DiscoveryOAuth2
112+ )
113+
114+ func (s * Server ) discoveryHandler (t DiscoveryType ) (http.HandlerFunc , error ) {
115+ var d interface {}
116+
117+ switch t {
118+ case DiscoveryOAuth2 :
119+ d = s .constructDiscoveryOAuth2 ()
120+ default :
121+ d = s .constructDiscoveryOIDC ()
122+ }
95123
96124 data , err := json .MarshalIndent (d , "" , " " )
97125 if err != nil {
@@ -105,8 +133,8 @@ func (s *Server) discoveryHandler() (http.HandlerFunc, error) {
105133 }), nil
106134}
107135
108- func (s * Server ) constructDiscovery () discovery {
109- d := discovery {
136+ func (s * Server ) constructDiscoveryOIDC () discoveryOIDC {
137+ d := discoveryOIDC {
110138 Issuer : s .issuerURL .String (),
111139 Auth : s .absURL ("/auth" ),
112140 Token : s .absURL ("/token" ),
@@ -134,6 +162,31 @@ func (s *Server) constructDiscovery() discovery {
134162 return d
135163}
136164
165+ func (s * Server ) constructDiscoveryOAuth2 () discoveryOAuth2 {
166+ d := discoveryOAuth2 {
167+ Issuer : s .issuerURL .String (),
168+ Auth : s .absURL ("/auth" ),
169+ Token : s .absURL ("/token" ),
170+ Keys : s .absURL ("/keys" ),
171+ DeviceEndpoint : s .absURL ("/device/code" ),
172+ Introspect : s .absURL ("/token/introspect" ),
173+ CodeChallengeAlgs : []string {codeChallengeMethodS256 , codeChallengeMethodPlain },
174+ Scopes : []string {"offline_access" },
175+ AuthMethods : []string {"client_secret_basic" , "client_secret_post" },
176+ }
177+
178+ // response_types_supported
179+ for responseType := range s .supportedResponseTypes {
180+ d .ResponseTypes = append (d .ResponseTypes , responseType )
181+ }
182+ sort .Strings (d .ResponseTypes )
183+
184+ // grant_types_supported
185+ d .GrantTypes = s .supportedGrantTypes
186+
187+ return d
188+ }
189+
137190// handleAuthorization handles the OAuth2 auth endpoint.
138191func (s * Server ) handleAuthorization (w http.ResponseWriter , r * http.Request ) {
139192 ctx := r .Context ()
0 commit comments