1
0

openid.go 2.0 KB

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