...
|
...
|
@@ -4,6 +4,7 @@ import ( |
|
|
"bytes"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
|
|
|
"html/template"
|
|
|
"strings"
|
|
|
"time"
|
...
|
...
|
@@ -83,6 +84,12 @@ Success: |
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if userInfo.Auth == "" {
|
|
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
|
|
}
|
|
|
if err = models.UpdateUserInfoById(userInfo); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.LoginResponse{AuthCode: userInfo.Auth}
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -99,19 +106,26 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr |
|
|
var (
|
|
|
userInfo *models.UserInfo
|
|
|
)
|
|
|
userInfo, err = models.GetUserInfoByClientId(request.ClientId)
|
|
|
_, err = models.GetCfgClient(request.ClientId, request.ClientSecret)
|
|
|
if err != nil {
|
|
|
common.NewError(101, err)
|
|
|
return
|
|
|
}
|
|
|
userInfo, err = models.GetUserInfoByAuthCode(request.AuthCode)
|
|
|
if err != nil {
|
|
|
common.NewError(4139, err)
|
|
|
return
|
|
|
}
|
|
|
if strings.Compare(userInfo.Auth, request.AuthCode) != 0 {
|
|
|
err = common.NewErrorWithMsg(2, "auth code error.")
|
|
|
userInfo.AccessToken = uid.NewV1().StringNoDash()
|
|
|
userInfo.RefreshToken = uid.NewV1().StringNoDash()
|
|
|
if err = models.UpdateUserInfoById(userInfo); err != nil {
|
|
|
return
|
|
|
}
|
|
|
//valid token
|
|
|
rsp = &protocol.AccessTokenResponse{
|
|
|
RefreshToken: userInfo.RefreshToken,
|
|
|
AccessToken: userInfo.AccessToken,
|
|
|
ExpiresIn: 3600,
|
|
|
ExpiresIn: protocol.TokenExpire,
|
|
|
}
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -122,33 +136,35 @@ func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp * |
|
|
userInfo *models.UserInfo
|
|
|
newAccess *protocol.Access
|
|
|
)
|
|
|
userInfo, err = models.GetUserInfoByClientId(request.ClientId)
|
|
|
_, err = models.GetCfgClient(request.ClientId, request.ClientSecret)
|
|
|
if err != nil {
|
|
|
common.NewError(101, err)
|
|
|
return
|
|
|
}
|
|
|
if strings.Compare(userInfo.RefreshToken, request.RefreshToken) != 0 {
|
|
|
err = common.NewErrorWithMsg(2, "refresh token error.")
|
|
|
userInfo, err = models.GetUserInfoByAuthCode(request.RefreshToken)
|
|
|
if err != nil {
|
|
|
common.NewError(4139, err)
|
|
|
return
|
|
|
}
|
|
|
request.Uid, request.LoginType = userInfo.Id, "mobile"
|
|
|
if newAccess, err = refreshToken(request); err != nil {
|
|
|
userInfo.AccessToken = uid.NewV1().StringNoDash()
|
|
|
if err = models.UpdateUserInfoById(userInfo); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.RefreshTokenResponse{
|
|
|
AccessToken: newAccess.AccessToken,
|
|
|
RefreshToken: newAccess.RefreshToken,
|
|
|
ExpiresIn: 3600,
|
|
|
ExpiresIn: protocol.TokenExpire,
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//刷新token loginType mobile im web
|
|
|
func refreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.Access, err error) {
|
|
|
if request.Uid == 0 {
|
|
|
return
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
//func refreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.Access, err error) {
|
|
|
// if request.Uid == 0 {
|
|
|
// return
|
|
|
// }
|
|
|
// return nil, nil
|
|
|
//}
|
|
|
|
|
|
//检查token有效性
|
|
|
func (s *AuthService) CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenResponse, err error) {
|
...
|
...
|
|