mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-06 22:44:03 +02:00
refactor(oidc): simplify exchange method
This commit is contained in:
parent
ef483403da
commit
077641beaa
1 changed files with 8 additions and 3 deletions
|
@ -182,13 +182,18 @@ func (auth *OIDCProvider) RedirectLoginPage(w http.ResponseWriter, r *http.Reque
|
||||||
http.Redirect(w, r, redirURL, http.StatusTemporaryRedirect)
|
http.Redirect(w, r, redirURL, http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (auth *OIDCProvider) exchange(r *http.Request) (*oauth2.Token, error) {
|
func (auth *OIDCProvider) cloneConfig() *oauth2.Config {
|
||||||
if auth.isMiddleware {
|
|
||||||
cfg := *auth.oauthConfig
|
cfg := *auth.oauthConfig
|
||||||
cfg.RedirectURL = "https://" + r.Host + OIDCMiddlewareCallbackPath
|
return &cfg
|
||||||
return cfg.Exchange(r.Context(), r.URL.Query().Get("code"))
|
|
||||||
}
|
}
|
||||||
return auth.oauthConfig.Exchange(r.Context(), r.URL.Query().Get("code"))
|
|
||||||
|
func (auth *OIDCProvider) exchange(r *http.Request) (*oauth2.Token, error) {
|
||||||
|
var cfg *oauth2.Config
|
||||||
|
if auth.isMiddleware {
|
||||||
|
cfg = auth.cloneConfig()
|
||||||
|
cfg.RedirectURL = "https://" + r.Host + OIDCMiddlewareCallbackPath
|
||||||
|
}
|
||||||
|
return cfg.Exchange(r.Context(), r.URL.Query().Get("code"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OIDCCallbackHandler handles the OIDC callback.
|
// OIDCCallbackHandler handles the OIDC callback.
|
||||||
|
|
Loading…
Add table
Reference in a new issue