Adding force https metadata key (#487)
* adding force https metadata and its handler code * make https a const; change ForceHTTPS to lowercase before compare with true * replacing strings.ToLower with strings.EqualFold due to lint error in Build linux_amd64 binaries check Co-authored-by: Yaron Schneider <yaronsc@microsoft.com> Co-authored-by: Young Bu Park <youngp@microsoft.com>
This commit is contained in:
parent
ed7480237d
commit
5e9140f1db
|
@ -26,6 +26,7 @@ type oAuth2MiddlewareMetadata struct {
|
|||
TokenURL string `json:"tokenURL"`
|
||||
AuthHeaderName string `json:"authHeaderName"`
|
||||
RedirectURL string `json:"redirectURL"`
|
||||
ForceHTTPS string `json:"forceHTTPS"`
|
||||
}
|
||||
|
||||
// NewOAuth2Middleware returns a new oAuth2 middleware
|
||||
|
@ -42,6 +43,7 @@ const (
|
|||
savedState = "auth-state"
|
||||
redirectPath = "redirect-url"
|
||||
codeParam = "code"
|
||||
https = "https://"
|
||||
)
|
||||
|
||||
// GetHandler retruns the HTTP handler provided by the middleware
|
||||
|
@ -81,6 +83,9 @@ func (m *Middleware) GetHandler(metadata middleware.Metadata) (func(h fasthttp.R
|
|||
} else {
|
||||
authState := session.GetString(savedState)
|
||||
redirectURL := session.GetString(redirectPath)
|
||||
if strings.EqualFold(meta.ForceHTTPS, "true") {
|
||||
redirectURL = https + string(ctx.Request.Host()) + redirectURL
|
||||
}
|
||||
if state != authState {
|
||||
ctx.Error("invalid state", fasthttp.StatusBadRequest)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue