Move actual implementation of default provider GetLoginURL into DefaultGetLoginURL

This allows us to reuse code from different providers in case slight
modifications to the URL are needed.
This commit is contained in:
Alexander Block 2020-09-14 13:22:53 +02:00
parent 017b9bcfb7
commit 97e95fd4ff

View File

@ -73,8 +73,7 @@ func (p *ProviderData) Redeem(ctx context.Context, redirectURL, code string) (s
return
}
// GetLoginURL with typical oauth parameters
func (p *ProviderData) GetLoginURL(redirectURI, state string) string {
func DefaultGetLoginURL(p *ProviderData, redirectURI, state string) (url.URL, url.Values) {
a := *p.LoginURL
params, _ := url.ParseQuery(a.RawQuery)
params.Set("redirect_uri", redirectURI)
@ -93,6 +92,12 @@ func (p *ProviderData) GetLoginURL(redirectURI, state string) string {
if p.ProtectedResource != nil && p.ProtectedResource.String() != "" {
params.Add("resource", p.ProtectedResource.String())
}
return a, params
}
// GetLoginURL with typical oauth parameters
func (p *ProviderData) GetLoginURL(redirectURI, state string) string {
a, params := DefaultGetLoginURL(p, redirectURI, state)
a.RawQuery = params.Encode()
return a.String()
}