Skip to content

Commit

Permalink
Add WithRedirectURL option (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen authored Aug 29, 2022
1 parent 16ec487 commit 409e16b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion oauth2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,20 @@ func OnLogin(c LoginCallback) Param {
}
}

// WithRedirectURL sets a static redirect URL. By default, the redirect URL is
// generated using the request path, the Host header, and the ForceTLS option.
func WithRedirectURL(uri string) Param {
return func(h *handler) {
h.config.RedirectURL = uri
}
}

func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// copy config for modification
conf := *h.config
conf.RedirectURL = redirectURL(r, h.forceTLS)
if conf.RedirectURL == "" {
conf.RedirectURL = redirectURL(r, h.forceTLS)
}

// if the provider returned an error, abort the processes
if r.FormValue(queryError) != "" {
Expand Down

0 comments on commit 409e16b

Please sign in to comment.