From 8b921b2c1e488cfa640d7da764db3ce2634407ff Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sat, 20 Mar 2021 23:50:34 +0800 Subject: [PATCH] Fix double GET params issue, fix double state bug. --- controllers/auth.go | 9 +++++---- web/src/auth/AuthCallback.js | 3 +-- web/src/auth/Provider.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/auth.go b/controllers/auth.go index 62df8462..b278a3db 100644 --- a/controllers/auth.go +++ b/controllers/auth.go @@ -113,8 +113,9 @@ func (c *ApiController) Login() { var res authResponse - if form.State != beego.AppConfig.String("AuthState") { - resp = &Response{Status: "error", Msg: "unauthorized", Data: res} + if form.State != beego.AppConfig.String("AuthState") && form.State != application.Name { + resp = &Response{Status: "error", Msg: fmt.Sprintf("state expected: \"%s\", but got: \"%s\"", beego.AppConfig.String("AuthState"), form.State), Data: res} + c.Data["json"] = resp c.ServeJSON() return } @@ -127,7 +128,7 @@ func (c *ApiController) Login() { } if !token.Valid() { - resp = &Response{Status: "error", Msg: "unauthorized", Data: res} + resp = &Response{Status: "error", Msg: "invalid token", Data: res} c.Data["json"] = resp c.ServeJSON() return @@ -135,7 +136,7 @@ func (c *ApiController) Login() { res.Email, res.Method, res.Avatar, err = idProvider.GetUserInfo(httpClient, token) if err != nil { - resp = &Response{Status: "error", Msg: "Login failed, please try again."} + resp = &Response{Status: "error", Msg: "login failed, please try again."} c.Data["json"] = resp c.ServeJSON() return diff --git a/web/src/auth/AuthCallback.js b/web/src/auth/AuthCallback.js index 5976a50d..bb32d3ca 100644 --- a/web/src/auth/AuthCallback.js +++ b/web/src/auth/AuthCallback.js @@ -31,8 +31,7 @@ class AuthCallback extends React.Component { componentWillMount() { const params = new URLSearchParams(this.props.location.search); - let redirectUri; - redirectUri = `${window.location.origin}/callback/${this.state.applicationName}/${this.state.providerName}/${this.state.method}`; + let redirectUri = `${window.location.origin}/callback/${this.state.applicationName}/${this.state.providerName}/${this.state.method}`; const body = { application: this.state.applicationName, provider: this.state.providerName, diff --git a/web/src/auth/Provider.js b/web/src/auth/Provider.js index d64d5c44..80a45314 100644 --- a/web/src/auth/Provider.js +++ b/web/src/auth/Provider.js @@ -43,7 +43,7 @@ export function getAuthLogo(provider) { } export function getAuthUrl(application, provider, method) { - const redirectUri = `${window.location.origin}/callback/${application.name}/${provider.name}/${method}`; + const redirectUri = `${window.location.origin}/callback/${application.name}/${provider.name}/${method}${encodeURIComponent(window.location.search)}`; if (provider.type === "google") { return `${GoogleAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GoogleAuthScope}&response_type=code&state=${AuthState}`; } else if (provider.type === "github") {