@@ -60,8 +60,8 @@ func main() {
60
60
61
61
slog .Debug ("Keys" , "config.signingKeyPub" , base64url (config .signingKeyPub ))
62
62
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 )
65
65
http .HandleFunc ("/authorize" , config .authorizeHandler )
66
66
http .HandleFunc ("POST /token" , config .tokenHandler )
67
67
http .HandleFunc ("GET /keys" , config .keysHandler )
@@ -70,7 +70,7 @@ func main() {
70
70
http .ListenAndServe (config .address , nil )
71
71
}
72
72
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
74
74
func (config * config ) openidConfigurationHandler (w http.ResponseWriter , _ * http.Request ) {
75
75
fmt .Fprintf (w , `{
76
76
"issuer": "%s",
@@ -104,7 +104,9 @@ func (config *config) openidConfigurationHandler(w http.ResponseWriter, _ *http.
104
104
}%s` , config .issuer , config .issuer , config .issuer , config .issuer , "\n " )
105
105
}
106
106
107
+ // https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.1
107
108
func (config * config ) authorizeHandler (w http.ResponseWriter , r * http.Request ) {
109
+ // https://www.rfc-editor.org/rfc/rfc6749.txt#4.1.2.1
108
110
badRequest := func (msg string ) {
109
111
slog .Debug (msg )
110
112
http .Error (w , msg , http .StatusBadRequest )
@@ -176,6 +178,7 @@ func replaceAll(t string, params ...any) string {
176
178
return t
177
179
}
178
180
181
+ // https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.3.1
179
182
func (config * config ) tokenHandler (w http.ResponseWriter , r * http.Request ) {
180
183
unauthorized := func (msg string ) {
181
184
slog .Debug (msg )
@@ -264,16 +267,17 @@ func (config *config) tokenHandler(w http.ResponseWriter, r *http.Request) {
264
267
fmt .Fprintln (w , respBody )
265
268
}
266
269
270
+ // https://www.rfc-editor.org/rfc/rfc7517.txt#5
267
271
func (config * config ) keysHandler (w http.ResponseWriter , r * http.Request ) {
268
272
w .Header ().Set ("Content-Type" , "application/json" )
269
273
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 " )
277
281
slog .Debug ("Response" , "body" , respBody )
278
282
fmt .Fprintln (w , respBody )
279
283
}
0 commit comments