Skip to content

Commit

Permalink
fix fetch token
Browse files Browse the repository at this point in the history
  • Loading branch information
zengchen1024 committed Apr 10, 2021
1 parent d941aa2 commit 5fb4ac0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
13 changes: 7 additions & 6 deletions controllers/auth_on_code_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ func (this *AuthController) Callback() {
rs(errSystemError, err)
return
}

this.setCookies(map[string]string{apiAccessToken: at}, true)

cookies := map[string]string{"action": purpose, "platform": platform}
if permission == PermissionIndividualSigner {
this.setCookies(map[string]string{
"sign_user": pl.User,
"sign_email": pl.Email,
}, false)
cookies["sign_user"] = pl.User
cookies["sign_email"] = pl.Email
}
this.setCookies(cookies, false)

this.redirect(authHelper.WebRedirectDir(true))
}

Expand Down Expand Up @@ -160,7 +161,7 @@ func (this *AuthController) Auth() {
return
}

this.sendSuccessResp(map[string]string{"access_token": at})
this.sendSuccessResp(map[string]string{apiAccessToken: at})
}

func (this *AuthController) genACPayload(platform, permission, platformToken string) (*acForCodePlatformPayload, string, error) {
Expand Down
8 changes: 6 additions & 2 deletions controllers/base-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,13 @@ func (this *baseController) newAccessController(permission string) *accessContro
}

func (this *baseController) checkApiReqToken(ac *accessController, permission []string) *failedApiResult {
token := this.Ctx.Input.Cookie(apiAccessToken)
// Fetch token from Header firstly to avoid fetching wrong token when changing to login as corp manager
// from community manager. Because the token exists in the cookie always.
token := this.apiReqHeader(apiHeaderToken)
if token == "" {
return newFailedApiResult(401, errMissingToken, fmt.Errorf("no token passed"))
if token = this.Ctx.Input.Cookie(apiAccessToken); token == "" {
return newFailedApiResult(401, errMissingToken, fmt.Errorf("no token passed"))
}
}

if err := ac.parseToken(token, config.AppConfig.APITokenKey); err != nil {
Expand Down
1 change: 1 addition & 0 deletions controllers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

const (
apiHeaderToken = "Token"
apiAccessToken = "access_token"
apiAccessController = "access_controller"
contentTypeOfPDF = "application/pdf"
Expand Down

0 comments on commit 5fb4ac0

Please sign in to comment.