...
|
...
|
@@ -2,8 +2,10 @@ package auth |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/tiptok/gocomm/xa/eda"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/event"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/domain_service"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
|
...
|
...
|
@@ -124,13 +126,11 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke |
|
|
rsp.RefreshToken, _ = utils.GenerateTokenWithClaim(userClaims, protocol.RefreshTokenExipre*time.Second)
|
|
|
rsp.ExpiresIn = protocol.TokenExpire
|
|
|
|
|
|
//auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId),
|
|
|
// userAuth.WithAccessToken(rsp.AccessToken),
|
|
|
// userAuth.WithRefreshToken(rsp.RefreshToken))
|
|
|
//if err = auth.AddAuth(); err != nil {
|
|
|
// log.Error(err)
|
|
|
// return
|
|
|
//}
|
|
|
eda.Publish(&event.AccessTokenEvent{
|
|
|
UserPhone: claim.Phone,
|
|
|
AccessToken: rsp.AccessToken,
|
|
|
RefreshToken: rsp.RefreshToken,
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -192,12 +192,6 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT |
|
|
return
|
|
|
}
|
|
|
|
|
|
//oldAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId))
|
|
|
//if err = oldAuth.Check(userAuth.NewOptions(userAuth.WithRefreshToken(request.RefreshToken))); err != nil {
|
|
|
// log.Error(err)
|
|
|
// err = protocol.NewErrWithMessage(4140, err)
|
|
|
// return
|
|
|
//}
|
|
|
userClaim := utils.UserTokenClaims{
|
|
|
UserId: userId,
|
|
|
Phone: claim.Phone,
|
...
|
...
|
@@ -208,13 +202,19 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT |
|
|
rsp.RefreshToken, _ = utils.GenerateTokenWithClaim(userClaim, protocol.RefreshTokenExipre*time.Second)
|
|
|
rsp.ExpiresIn = protocol.TokenExpire
|
|
|
|
|
|
//newAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId),
|
|
|
// userAuth.WithAccessToken(rsp.AccessToken),
|
|
|
// userAuth.WithRefreshToken(rsp.RefreshToken))
|
|
|
//if err = newAuth.AddAuth(); err != nil {
|
|
|
// log.Error(err)
|
|
|
// return
|
|
|
//}
|
|
|
if err = eda.Publish(&event.RefreshTokenEvent{
|
|
|
UserPhone: claim.Phone,
|
|
|
AccessToken: rsp.AccessToken,
|
|
|
RefreshToken: rsp.RefreshToken,
|
|
|
OldRefreshToken: request.RefreshToken,
|
|
|
OldAccessToken: "",
|
|
|
}); err != nil {
|
|
|
log.Error(err)
|
|
|
rsp.RefreshToken = ""
|
|
|
rsp.AccessToken = ""
|
|
|
err = protocol.NewErrWithMessage(4140, err)
|
|
|
return
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
...
|
...
|
|