diff --git a/pkg/client/client.go b/pkg/client/client.go index 1828d1d..ac6cd56 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -26,8 +26,13 @@ var ( ) //Discover calls the discovery endpoint of the provided issuer and returns its configuration -func Discover(issuer string, httpClient *http.Client) (*oidc.DiscoveryConfiguration, error) { +//It accepts an optional argument "wellknownUrl" which can be used to overide the dicovery endpoint url +func Discover(issuer string, httpClient *http.Client, wellKnownUrl ...string) (*oidc.DiscoveryConfiguration, error) { + wellKnown := strings.TrimSuffix(issuer, "/") + oidc.DiscoveryEndpoint + if len(wellKnownUrl) == 1 && wellKnownUrl[0] != "" { + wellKnown = wellKnownUrl[0] + } req, err := http.NewRequest("GET", wellKnown, nil) if err != nil { return nil, err diff --git a/pkg/client/rp/relaying_party.go b/pkg/client/rp/relaying_party.go index 23c37fc..98ab354 100644 --- a/pkg/client/rp/relaying_party.go +++ b/pkg/client/rp/relaying_party.go @@ -69,11 +69,12 @@ var ( ) type relyingParty struct { - issuer string - endpoints Endpoints - oauthConfig *oauth2.Config - oauth2Only bool - pkce bool + issuer string + DiscoveryEndpoint string + endpoints Endpoints + oauthConfig *oauth2.Config + oauth2Only bool + pkce bool httpClient *http.Client cookieHandler *httphelper.CookieHandler @@ -170,7 +171,7 @@ func NewRelyingPartyOIDC(issuer, clientID, clientSecret, redirectURI string, sco return nil, err } } - discoveryConfiguration, err := client.Discover(rp.issuer, rp.httpClient) + discoveryConfiguration, err := client.Discover(rp.issuer, rp.httpClient, rp.DiscoveryEndpoint) if err != nil { return nil, err } @@ -184,6 +185,13 @@ func NewRelyingPartyOIDC(issuer, clientID, clientSecret, redirectURI string, sco //Option is the type for providing dynamic options to the relyingParty type Option func(*relyingParty) error +func WithCustomDiscoveryUrl(url string) Option { + return func(rp *relyingParty) error { + rp.DiscoveryEndpoint = url + return nil + } +} + //WithCookieHandler set a `CookieHandler` for securing the various redirects func WithCookieHandler(cookieHandler *httphelper.CookieHandler) Option { return func(rp *relyingParty) error {