mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2024-11-28 09:08:44 +02:00
Move DefaultGetLoginURL into util.go
This commit is contained in:
parent
9a64e67d5b
commit
4eb9612679
@ -212,7 +212,7 @@ func (p *AzureProvider) GetEmailAddress(ctx context.Context, s *sessions.Session
|
||||
}
|
||||
|
||||
func (p *AzureProvider) GetLoginURL(redirectURI, state string) string {
|
||||
a, params := DefaultGetLoginURL(p.ProviderData, redirectURI, state)
|
||||
a, params := makeLoginURL(p.ProviderData, redirectURI, state)
|
||||
if p.ProtectedResource != nil && p.ProtectedResource.String() != "" {
|
||||
params.Add("resource", p.ProtectedResource.String())
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ func (p *LoginGovProvider) Redeem(ctx context.Context, redirectURL, code string)
|
||||
|
||||
// GetLoginURL overrides GetLoginURL to add login.gov parameters
|
||||
func (p *LoginGovProvider) GetLoginURL(redirectURI, state string) string {
|
||||
a, params := DefaultGetLoginURL(p.ProviderData, redirectURI, state)
|
||||
a, params := makeLoginURL(p.ProviderData, redirectURI, state)
|
||||
if p.AcrValues == "" {
|
||||
acr := "http://idmanagement.gov/ns/assurance/loa/1"
|
||||
params.Add("acr_values", acr)
|
||||
|
@ -73,28 +73,9 @@ func (p *ProviderData) Redeem(ctx context.Context, redirectURL, code string) (s
|
||||
return
|
||||
}
|
||||
|
||||
func DefaultGetLoginURL(p *ProviderData, redirectURI, state string) (url.URL, url.Values) {
|
||||
a := *p.LoginURL
|
||||
params, _ := url.ParseQuery(a.RawQuery)
|
||||
params.Set("redirect_uri", redirectURI)
|
||||
if p.AcrValues != "" {
|
||||
params.Add("acr_values", p.AcrValues)
|
||||
}
|
||||
if p.Prompt != "" {
|
||||
params.Set("prompt", p.Prompt)
|
||||
} else { // Legacy variant of the prompt param:
|
||||
params.Set("approval_prompt", p.ApprovalPrompt)
|
||||
}
|
||||
params.Add("scope", p.Scope)
|
||||
params.Set("client_id", p.ClientID)
|
||||
params.Set("response_type", "code")
|
||||
params.Add("state", state)
|
||||
return a, params
|
||||
}
|
||||
|
||||
// GetLoginURL with typical oauth parameters
|
||||
func (p *ProviderData) GetLoginURL(redirectURI, state string) string {
|
||||
a, params := DefaultGetLoginURL(p, redirectURI, state)
|
||||
a, params := makeLoginURL(p, redirectURI, state)
|
||||
a.RawQuery = params.Encode()
|
||||
return a.String()
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package providers
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -29,3 +30,22 @@ func makeOIDCHeader(accessToken string) http.Header {
|
||||
}
|
||||
return makeAuthorizationHeader(tokenTypeBearer, accessToken, extraHeaders)
|
||||
}
|
||||
|
||||
func makeLoginURL(p *ProviderData, redirectURI, state string) (url.URL, url.Values) {
|
||||
a := *p.LoginURL
|
||||
params, _ := url.ParseQuery(a.RawQuery)
|
||||
params.Set("redirect_uri", redirectURI)
|
||||
if p.AcrValues != "" {
|
||||
params.Add("acr_values", p.AcrValues)
|
||||
}
|
||||
if p.Prompt != "" {
|
||||
params.Set("prompt", p.Prompt)
|
||||
} else { // Legacy variant of the prompt param:
|
||||
params.Set("approval_prompt", p.ApprovalPrompt)
|
||||
}
|
||||
params.Add("scope", p.Scope)
|
||||
params.Set("client_id", p.ClientID)
|
||||
params.Set("response_type", "code")
|
||||
params.Add("state", state)
|
||||
return a, params
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user