Browse Source

Added openid discovery request handler

Toby Chui 5 months ago
parent
commit
e92bceca37
2 changed files with 52 additions and 0 deletions
  1. 49 0
      mod/auth/sso/openid.go
  2. 3 0
      mod/auth/sso/server.go

+ 49 - 0
mod/auth/sso/openid.go

@@ -0,0 +1,49 @@
+package sso
+
+import (
+	"encoding/json"
+	"net/http"
+)
+
+type OpenIDConfiguration struct {
+	Issuer                           string   `json:"issuer"`
+	AuthorizationEndpoint            string   `json:"authorization_endpoint"`
+	TokenEndpoint                    string   `json:"token_endpoint"`
+	JwksUri                          string   `json:"jwks_uri"`
+	ResponseTypesSupported           []string `json:"response_types_supported"`
+	SubjectTypesSupported            []string `json:"subject_types_supported"`
+	IDTokenSigningAlgValuesSupported []string `json:"id_token_signing_alg_values_supported"`
+	ClaimsSupported                  []string `json:"claims_supported"`
+}
+
+func (h *SSOHandler) HandleDiscoveryRequest(w http.ResponseWriter, r *http.Request) {
+	//Handle the discovery request
+	discovery := OpenIDConfiguration{
+		Issuer:                 "https://" + h.Config.AuthURL,
+		AuthorizationEndpoint:  "https://" + h.Config.AuthURL + "/oauth2/auth",
+		TokenEndpoint:          "https://" + h.Config.AuthURL + "/oauth2/token",
+		JwksUri:                "https://" + h.Config.AuthURL + "/jwks.json",
+		ResponseTypesSupported: []string{"code", "token"},
+		SubjectTypesSupported:  []string{"public"},
+		IDTokenSigningAlgValuesSupported: []string{
+			"RS256",
+		},
+		ClaimsSupported: []string{
+			"sub",                //Subject, usually the user ID
+			"iss",                //Issuer, usually the server URL
+			"aud",                //Audience, usually the client ID
+			"exp",                //Expiration Time
+			"iat",                //Issued At
+			"email",              //Email
+			"locale",             //Locale
+			"name",               //Full Name
+			"nickname",           //Nickname
+			"preferred_username", //Preferred Username
+			"website",            //Website
+		},
+	}
+
+	//Write the response
+	js, _ := json.Marshal(discovery)
+	w.Write(js)
+}

+ 3 - 0
mod/auth/sso/server.go

@@ -31,6 +31,9 @@ func (h *SSOHandler) InitSSOPortal(portalServerPort int) {
 	//Register API endpoint for the SSO portal
 	pmux.HandleFunc("/sso/login", h.HandleLogin)
 
+	//Register API endpoint for autodiscovery
+	pmux.HandleFunc("/.well-known/openid-configuration", h.HandleDiscoveryRequest)
+
 	//Register OAuth2 endpoints
 	h.Oauth2Server.RegisterOauthEndpoints(pmux)
 	h.ssoPortalMux = pmux