From 4d2d193d1c3067dd1a24899ae1af3d59bedc5b0e Mon Sep 17 00:00:00 2001 From: ydris Date: Wed, 26 Jan 2022 17:23:54 +0100 Subject: [PATCH] Allow the use of custom endpoints --- pkg/client/rp/relaying_party.go | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/client/rp/relaying_party.go b/pkg/client/rp/relaying_party.go index 23c37fc..4ed5eef 100644 --- a/pkg/client/rp/relaying_party.go +++ b/pkg/client/rp/relaying_party.go @@ -181,6 +181,42 @@ func NewRelyingPartyOIDC(issuer, clientID, clientSecret, redirectURI string, sco return rp, nil } +//NewRelyingPartyOIDCWithCustomEndpoints creates an (OIDC) RelyingParty with the given +//discoveryConfiguration, clientID, clientSecret, redirectURI, scopes and other possible configOptions +//it will use the provided end points +//This is usefull when the server does not use standard endpoint paths +func NewRelyingPartyOIDCWithCustomEndpoints( + discoveryConfiguration *oidc.DiscoveryConfiguration, + clientID, + clientSecret, + redirectURI string, + scopes []string, + options ...Option) (RelyingParty, error) { + + rp := &relyingParty{ + issuer: discoveryConfiguration.Issuer, + oauthConfig: &oauth2.Config{ + ClientID: clientID, + ClientSecret: clientSecret, + RedirectURL: redirectURI, + Scopes: scopes, + }, + httpClient: httphelper.DefaultHTTPClient, + oauth2Only: false, + } + + for _, optFunc := range options { + if err := optFunc(rp); err != nil { + return nil, err + } + } + endpoints := GetEndpoints(discoveryConfiguration) + rp.oauthConfig.Endpoint = endpoints.Endpoint + rp.endpoints = endpoints + + return rp, nil +} + //Option is the type for providing dynamic options to the relyingParty type Option func(*relyingParty) error