mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-25 11:44:16 +00:00
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package labeler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// DIDDocument represents a did:web DID document.
|
|
type DIDDocument struct {
|
|
Context []string `json:"@context"`
|
|
ID string `json:"id"`
|
|
Service []DIDService `json:"service,omitempty"`
|
|
}
|
|
|
|
// DIDService represents a service entry in a DID document.
|
|
type DIDService struct {
|
|
ID string `json:"id"`
|
|
Type string `json:"type"`
|
|
ServiceEndpoint string `json:"serviceEndpoint"`
|
|
}
|
|
|
|
func (s *Server) handleDIDDocument(w http.ResponseWriter, r *http.Request) {
|
|
doc := DIDDocument{
|
|
Context: []string{"https://www.w3.org/ns/did/v1"},
|
|
ID: s.config.DID(),
|
|
Service: []DIDService{
|
|
{
|
|
ID: "#atproto_labeler",
|
|
Type: "AtprotoLabeler",
|
|
ServiceEndpoint: s.config.PublicURL(),
|
|
},
|
|
},
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_ = json.NewEncoder(w).Encode(doc)
|
|
}
|
|
|
|
func (s *Server) handleClientMetadata(w http.ResponseWriter, r *http.Request) {
|
|
publicURL := s.config.PublicURL()
|
|
metadata := map[string]any{
|
|
"client_id": publicURL + "/oauth-client-metadata.json",
|
|
"client_name": fmt.Sprintf("%s Labeler", s.config.Server.ClientShortName),
|
|
"client_uri": publicURL,
|
|
"redirect_uris": []string{publicURL + "/auth/oauth/callback"},
|
|
"scope": "atproto",
|
|
"grant_types": []string{"authorization_code"},
|
|
"response_types": []string{"code"},
|
|
"token_endpoint_auth_method": "none",
|
|
"application_type": "web",
|
|
"dpop_bound_access_tokens": true,
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_ = json.NewEncoder(w).Encode(metadata)
|
|
}
|