...
|
...
|
@@ -152,12 +152,12 @@ func (svr AuthService) AuthLoginQrcodeBinding(bindingCmd *command.QrcodeBindingC |
|
|
qrmsg := domain.QrcodeMessage{}
|
|
|
err := qrmsg.ParseToken(bindingCmd.Key)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "二维码已失效,请重试")
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "您扫描的二维码无效,请确认后重新扫描")
|
|
|
}
|
|
|
qrCache := cache.LoginQrcodeCache{}
|
|
|
qrmsgCache, err := qrCache.Get(qrmsg.Id)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "您扫描的二维码无效,请确认后重新扫描")
|
|
|
}
|
|
|
if err := qrmsgCache.BindUser(bindingCmd.Operator); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -240,14 +240,28 @@ func (svr AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke |
|
|
|
|
|
func (svr AuthService) RefreshAuthAccessToken(refreshTokenCommand *command.RefreshTokenCommand) (interface{}, error) {
|
|
|
if err := refreshTokenCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return nil, domain.NewApplicationError(domain.InvalidRefreshToken)
|
|
|
}
|
|
|
loginToken := domain.LoginToken{}
|
|
|
err := loginToken.ParseToken(refreshTokenCommand.RefreshToken)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "refreshToken 不可用,"+err.Error())
|
|
|
return nil, domain.NewApplicationError(domain.InvalidRefreshToken)
|
|
|
}
|
|
|
//redis缓存
|
|
|
tokenCache := cache.LoginTokenCache{}
|
|
|
refreshToken, err := tokenCache.GetRefreshToken(loginToken.Account, loginToken.Platform)
|
|
|
if err != nil {
|
|
|
log.Logger.Debug(err.Error())
|
|
|
return nil, domain.NewApplicationError(domain.InvalidRefreshToken)
|
|
|
}
|
|
|
if refreshToken != refreshTokenCommand.RefreshToken {
|
|
|
return nil, domain.NewApplicationError(domain.InvalidRefreshToken)
|
|
|
}
|
|
|
|
|
|
token, err := svr.getToken(loginToken)
|
|
|
if err != nil {
|
|
|
return nil, domain.NewApplicationError(domain.InvalidRefreshToken)
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"access": token["token"],
|
|
|
}, err
|
...
|
...
|
@@ -540,14 +554,18 @@ loopUser1: |
|
|
|
|
|
//redis缓存
|
|
|
tokenCache := cache.LoginTokenCache{}
|
|
|
tokenCache.RemoveAccessToken(currentAccess.Account, loginToken.Platform)
|
|
|
tokenCache.RemoveRefreshToken(currentAccess.Account, loginToken.Platform)
|
|
|
tokenCache.SaveAccessToken(currentAccess)
|
|
|
tokenCache.SaveRefreshToken(currentAccess)
|
|
|
|
|
|
//todo:error handler
|
|
|
if err = tokenCache.SaveAccessToken(currentAccess); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if err = tokenCache.SaveRefreshToken(currentAccess); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
nowTime := time.Now().Unix()
|
|
|
token := map[string]interface{}{
|
|
|
"refreshToken": accessTokenStr,
|
|
|
"accessToken": refreshTokenStr,
|
|
|
"refreshToken": refreshTokenStr,
|
|
|
"accessToken": accessTokenStr,
|
|
|
"expiresIn": currentAccess.AccessExpired - nowTime,
|
|
|
}
|
|
|
return map[string]interface{}{
|
...
|
...
|
|