@@ -71,7 +71,7 @@ func (s *Server) handlePublicKeys(w http.ResponseWriter, r *http.Request) {
7171 w .Write (data )
7272}
7373
74- type discovery struct {
74+ type discoveryOIDC struct {
7575 Issuer string `json:"issuer"`
7676 Auth string `json:"authorization_endpoint"`
7777 Token string `json:"token_endpoint"`
@@ -89,8 +89,36 @@ type discovery struct {
8989 Claims []string `json:"claims_supported"`
9090}
9191
92- func (s * Server ) discoveryHandler (ctx context.Context ) (http.HandlerFunc , error ) {
93- d := s .constructDiscovery (ctx )
92+ type discoveryOAuth2 struct {
93+ Issuer string `json:"issuer"`
94+ Auth string `json:"authorization_endpoint"`
95+ Token string `json:"token_endpoint"`
96+ Keys string `json:"jwks_uri"`
97+ DeviceEndpoint string `json:"device_authorization_endpoint,omitempty"`
98+ Introspect string `json:"introspection_endpoint,omitempty"`
99+ GrantTypes []string `json:"grant_types_supported"`
100+ ResponseTypes []string `json:"response_types_supported"`
101+ CodeChallengeAlgs []string `json:"code_challenge_methods_supported,omitempty"`
102+ Scopes []string `json:"scopes_supported,omitempty"`
103+ AuthMethods []string `json:"token_endpoint_auth_methods_supported,omitempty"`
104+ }
105+
106+ type DiscoveryType int
107+
108+ const (
109+ DiscoveryOIDC DiscoveryType = iota
110+ DiscoveryOAuth2
111+ )
112+
113+ func (s * Server ) discoveryHandler (ctx context.Context , t DiscoveryType ) (http.HandlerFunc , error ) {
114+ var d interface {}
115+
116+ switch t {
117+ case DiscoveryOAuth2 :
118+ d = s .constructDiscoveryOAuth2 ()
119+ default :
120+ d = s .constructDiscoveryOIDC (ctx )
121+ }
94122
95123 data , err := json .MarshalIndent (d , "" , " " )
96124 if err != nil {
@@ -104,8 +132,8 @@ func (s *Server) discoveryHandler(ctx context.Context) (http.HandlerFunc, error)
104132 }), nil
105133}
106134
107- func (s * Server ) constructDiscovery (ctx context.Context ) discovery {
108- d := discovery {
135+ func (s * Server ) constructDiscoveryOIDC (ctx context.Context ) discoveryOIDC {
136+ d := discoveryOIDC {
109137 Issuer : s .issuerURL .String (),
110138 Auth : s .absURL ("/auth" ),
111139 Token : s .absURL ("/token" ),
@@ -141,6 +169,31 @@ func (s *Server) constructDiscovery(ctx context.Context) discovery {
141169 return d
142170}
143171
172+ func (s * Server ) constructDiscoveryOAuth2 () discoveryOAuth2 {
173+ d := discoveryOAuth2 {
174+ Issuer : s .issuerURL .String (),
175+ Auth : s .absURL ("/auth" ),
176+ Token : s .absURL ("/token" ),
177+ Keys : s .absURL ("/keys" ),
178+ DeviceEndpoint : s .absURL ("/device/code" ),
179+ Introspect : s .absURL ("/token/introspect" ),
180+ CodeChallengeAlgs : []string {codeChallengeMethodS256 , codeChallengeMethodPlain },
181+ Scopes : []string {"offline_access" },
182+ AuthMethods : []string {"client_secret_basic" , "client_secret_post" },
183+ }
184+
185+ // response_types_supported
186+ for responseType := range s .supportedResponseTypes {
187+ d .ResponseTypes = append (d .ResponseTypes , responseType )
188+ }
189+ sort .Strings (d .ResponseTypes )
190+
191+ // grant_types_supported
192+ d .GrantTypes = s .supportedGrantTypes
193+
194+ return d
195+ }
196+
144197// handleAuthorization handles the OAuth2 auth endpoint.
145198func (s * Server ) handleAuthorization (w http.ResponseWriter , r * http.Request ) {
146199 ctx := r .Context ()
0 commit comments