openid.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package sso
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. )
  6. type OpenIDConfiguration struct {
  7. Issuer string `json:"issuer"`
  8. AuthorizationEndpoint string `json:"authorization_endpoint"`
  9. TokenEndpoint string `json:"token_endpoint"`
  10. JwksUri string `json:"jwks_uri"`
  11. ResponseTypesSupported []string `json:"response_types_supported"`
  12. SubjectTypesSupported []string `json:"subject_types_supported"`
  13. IDTokenSigningAlgValuesSupported []string `json:"id_token_signing_alg_values_supported"`
  14. ClaimsSupported []string `json:"claims_supported"`
  15. }
  16. func (h *SSOHandler) HandleDiscoveryRequest(w http.ResponseWriter, r *http.Request) {
  17. //Handle the discovery request
  18. discovery := OpenIDConfiguration{
  19. Issuer: "https://" + h.Config.AuthURL,
  20. AuthorizationEndpoint: "https://" + h.Config.AuthURL + "/oauth2/auth",
  21. TokenEndpoint: "https://" + h.Config.AuthURL + "/oauth2/token",
  22. JwksUri: "https://" + h.Config.AuthURL + "/jwks.json",
  23. ResponseTypesSupported: []string{"code", "token"},
  24. SubjectTypesSupported: []string{"public"},
  25. IDTokenSigningAlgValuesSupported: []string{
  26. "RS256",
  27. },
  28. ClaimsSupported: []string{
  29. "sub", //Subject, usually the user ID
  30. "iss", //Issuer, usually the server URL
  31. "aud", //Audience, usually the client ID
  32. "exp", //Expiration Time
  33. "iat", //Issued At
  34. "email", //Email
  35. "locale", //Locale
  36. "name", //Full Name
  37. "nickname", //Nickname
  38. "preferred_username", //Preferred Username
  39. "website", //Website
  40. },
  41. }
  42. //Write the response
  43. js, _ := json.Marshal(discovery)
  44. w.Write(js)
  45. }