From 97e95fd4ffe4887fe2a334d78c0279d2f30d46a5 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Mon, 14 Sep 2020 13:22:53 +0200 Subject: [PATCH] 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. --- providers/provider_default.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/providers/provider_default.go b/providers/provider_default.go index f20fe68..6e898a8 100644 --- a/providers/provider_default.go +++ b/providers/provider_default.go @@ -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() }