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:
Stepan 2020-10-23 00:51:07 +03:00 committed by GitHub
parent ed7480237d
commit 5e9140f1db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -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 {