Merge pull request #42 from shashimalcse/fix-baseurl
Some checks failed
Go CI / Test (push) Failing after 31s
Go CI / Build (push) Successful in 1m2s

get base url from the config for wellknownhandler
This commit is contained in:
Thilina Shashimal Senarath 2025-09-25 12:47:47 +05:30 committed by GitHub
commit 017a3f3a13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 37 deletions

View file

@ -42,31 +42,17 @@ func (p *asgardeoProvider) WellKnownHandler() http.HandlerFunc {
return return
} }
scheme := "http"
if r.TLS != nil {
scheme = "https"
}
if forwardedProto := r.Header.Get("X-Forwarded-Proto"); forwardedProto != "" {
scheme = forwardedProto
}
host := r.Host
if forwardedHost := r.Header.Get("X-Forwarded-Host"); forwardedHost != "" {
host = forwardedHost
}
baseURL := scheme + "://" + host
issuer := strings.TrimSuffix(p.cfg.AuthServerBaseURL, "/") + "/token" issuer := strings.TrimSuffix(p.cfg.AuthServerBaseURL, "/") + "/token"
response := map[string]interface{}{ response := map[string]interface{}{
"issuer": issuer, "issuer": issuer,
"authorization_endpoint": baseURL + "/authorize", "authorization_endpoint": p.cfg.BaseURL + "/authorize",
"token_endpoint": baseURL + "/token", "token_endpoint": p.cfg.BaseURL + "/token",
"jwks_uri": p.cfg.JWKSURL, "jwks_uri": p.cfg.JWKSURL,
"response_types_supported": []string{"code"}, "response_types_supported": []string{"code"},
"grant_types_supported": []string{"authorization_code", "refresh_token"}, "grant_types_supported": []string{"authorization_code", "refresh_token"},
"token_endpoint_auth_methods_supported": []string{"client_secret_basic"}, "token_endpoint_auth_methods_supported": []string{"client_secret_basic"},
"registration_endpoint": baseURL + "/register", "registration_endpoint": p.cfg.BaseURL + "/register",
"code_challenge_methods_supported": []string{"plain", "S256"}, "code_challenge_methods_supported": []string{"plain", "S256"},
} }

View file

@ -40,31 +40,17 @@ func (p *defaultProvider) WellKnownHandler() http.HandlerFunc {
// Use configured response values // Use configured response values
responseConfig := pathConfig.Response responseConfig := pathConfig.Response
// Get current host for proxy endpoints
scheme := "http"
if r.TLS != nil {
scheme = "https"
}
if forwardedProto := r.Header.Get("X-Forwarded-Proto"); forwardedProto != "" {
scheme = forwardedProto
}
host := r.Host
if forwardedHost := r.Header.Get("X-Forwarded-Host"); forwardedHost != "" {
host = forwardedHost
}
baseURL := scheme + "://" + host
authorizationEndpoint := responseConfig.AuthorizationEndpoint authorizationEndpoint := responseConfig.AuthorizationEndpoint
if authorizationEndpoint == "" { if authorizationEndpoint == "" {
authorizationEndpoint = baseURL + "/authorize" authorizationEndpoint = p.cfg.BaseURL + "/authorize"
} }
tokenEndpoint := responseConfig.TokenEndpoint tokenEndpoint := responseConfig.TokenEndpoint
if tokenEndpoint == "" { if tokenEndpoint == "" {
tokenEndpoint = baseURL + "/token" tokenEndpoint = p.cfg.BaseURL + "/token"
} }
registraionEndpoint := responseConfig.RegistrationEndpoint registrationEndpoint := responseConfig.RegistrationEndpoint
if registraionEndpoint == "" { if registrationEndpoint == "" {
registraionEndpoint = baseURL + "/register" registrationEndpoint = p.cfg.BaseURL + "/register"
} }
// Build response from config // Build response from config
@ -76,7 +62,7 @@ func (p *defaultProvider) WellKnownHandler() http.HandlerFunc {
"response_types_supported": responseConfig.ResponseTypesSupported, "response_types_supported": responseConfig.ResponseTypesSupported,
"grant_types_supported": responseConfig.GrantTypesSupported, "grant_types_supported": responseConfig.GrantTypesSupported,
"token_endpoint_auth_methods_supported": []string{"client_secret_basic"}, "token_endpoint_auth_methods_supported": []string{"client_secret_basic"},
"registration_endpoint": registraionEndpoint, "registration_endpoint": registrationEndpoint,
"code_challenge_methods_supported": responseConfig.CodeChallengeMethodsSupported, "code_challenge_methods_supported": responseConfig.CodeChallengeMethodsSupported,
} }