1// oauth/atproto/http.go
2package atproto
3
4import (
5 "encoding/json"
6 "fmt"
7 "net/http"
8)
9
10func strPtr(raw string) *string {
11 return &raw
12}
13
14func (a *ATprotoAuthService) HandleJwks(w http.ResponseWriter, r *http.Request) {
15 w.Header().Set("Content-Type", "application/json")
16 body := a.clientApp.Config.PublicJWKS()
17 if err := json.NewEncoder(w).Encode(body); err != nil {
18 http.Error(w, err.Error(), http.StatusInternalServerError)
19 return
20 }
21}
22
23func (a *ATprotoAuthService) HandleClientMetadata(w http.ResponseWriter, r *http.Request, serverUrlRoot, serverMetadataUrl, serverCallbackUrl string) {
24
25 meta := a.clientApp.Config.ClientMetadata()
26 if a.clientApp.Config.IsConfidential() {
27 meta.JWKSURI = strPtr(fmt.Sprintf("%s/oauth/jwks.json", serverUrlRoot))
28 }
29 meta.ClientName = strPtr("Piper Telekinesis")
30 meta.ClientURI = strPtr(serverUrlRoot)
31
32 // internal consistency check
33 if err := meta.Validate(a.clientApp.Config.ClientID); err != nil {
34 a.logger.Printf("validating client metadata", "err", err)
35 http.Error(w, err.Error(), http.StatusInternalServerError)
36 return
37 }
38
39 w.Header().Set("Content-Type", "application/json")
40 if err := json.NewEncoder(w).Encode(meta); err != nil {
41 http.Error(w, err.Error(), http.StatusInternalServerError)
42 return
43 }
44
45}