-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
41 lines (36 loc) · 1.34 KB
/
metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package oauth2
import (
"net/http"
)
// ServerMetadata is a struct that contains metadata according to RFC 8414.
//
// See https://datatracker.ietf.org/doc/rfc8414/.
type ServerMetadata struct {
Issuer string `json:"issuer"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
TokenEndpoint string `json:"token_endpoint"`
JWKSURI string `json:"jwks_uri"`
SupportedScopes []string `json:"scopes_supported"`
SupportedResponseTypes []string `json:"response_types_supported"`
SupportedGrantTypes []string `json:"grant_types_supported"`
}
// buildMetadata builds a [ServerMetadata] based on the capabilities of this
// server and the public URL.
func buildMetadata(url string) *ServerMetadata {
return &ServerMetadata{
Issuer: url,
AuthorizationEndpoint: url + "/authorize",
TokenEndpoint: url + "/token",
JWKSURI: url + "/certs",
SupportedScopes: []string{"profile"},
SupportedResponseTypes: []string{"code"},
SupportedGrantTypes: []string{"authorization_code", "client_credentials", "refresh_token"},
}
}
func (srv *AuthorizationServer) handleMetadata(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
srv.writeJSON(w, srv.metadata)
}