Skip to content

Commit e44722d

Browse files
Add RFC links
1 parent fbf3e94 commit e44722d

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

main.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func main() {
6060

6161
slog.Debug("Keys", "config.signingKeyPub", base64url(config.signingKeyPub))
6262

63-
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "I'm OK") })
64-
http.HandleFunc("/.well-known/openid-configuration", config.openidConfigurationHandler)
63+
http.HandleFunc("GET /health", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "I'm OK") })
64+
http.HandleFunc("GET /.well-known/openid-configuration", config.openidConfigurationHandler)
6565
http.HandleFunc("/authorize", config.authorizeHandler)
6666
http.HandleFunc("POST /token", config.tokenHandler)
6767
http.HandleFunc("GET /keys", config.keysHandler)
@@ -70,7 +70,7 @@ func main() {
7070
http.ListenAndServe(config.address, nil)
7171
}
7272

73-
// https://openid.net/specs/openid-connect-discovery-1_0.html
73+
// https://openid.net/specs/openid-connect-discovery-1_0.html#rfc.section.4
7474
func (config *config) openidConfigurationHandler(w http.ResponseWriter, _ *http.Request) {
7575
fmt.Fprintf(w, `{
7676
"issuer": "%s",
@@ -104,7 +104,9 @@ func (config *config) openidConfigurationHandler(w http.ResponseWriter, _ *http.
104104
}%s`, config.issuer, config.issuer, config.issuer, config.issuer, "\n")
105105
}
106106

107+
// https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.1
107108
func (config *config) authorizeHandler(w http.ResponseWriter, r *http.Request) {
109+
// https://www.rfc-editor.org/rfc/rfc6749.txt#4.1.2.1
108110
badRequest := func(msg string) {
109111
slog.Debug(msg)
110112
http.Error(w, msg, http.StatusBadRequest)
@@ -176,6 +178,7 @@ func replaceAll(t string, params ...any) string {
176178
return t
177179
}
178180

181+
// https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.3.1
179182
func (config *config) tokenHandler(w http.ResponseWriter, r *http.Request) {
180183
unauthorized := func(msg string) {
181184
slog.Debug(msg)
@@ -264,16 +267,17 @@ func (config *config) tokenHandler(w http.ResponseWriter, r *http.Request) {
264267
fmt.Fprintln(w, respBody)
265268
}
266269

270+
// https://www.rfc-editor.org/rfc/rfc7517.txt#5
267271
func (config *config) keysHandler(w http.ResponseWriter, r *http.Request) {
268272
w.Header().Set("Content-Type", "application/json")
269273
respBody := fmt.Sprintf(`{
270-
"keys": [
271-
{
272-
"kty":"OKP",
273-
"crv":"Ed25519",
274-
"x":"%s"
275-
}
276-
]}%s`, base64url(config.signingKeyPub), "\n")
274+
"keys": [
275+
{
276+
"kty":"OKP",
277+
"crv":"Ed25519",
278+
"x":"%s"
279+
}
280+
]}%s`, base64url(config.signingKeyPub), "\n")
277281
slog.Debug("Response", "body", respBody)
278282
fmt.Fprintln(w, respBody)
279283
}

0 commit comments

Comments
 (0)