checkauthlogic.go 915 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package logic
  2. import (
  3. "context"
  4. "ylink/apis/auth/pb"
  5. "ylink/bff/authbff/internal/svc"
  6. "ylink/bff/authbff/internal/types"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. type CheckAuthLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewCheckAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckAuthLogic {
  15. return &CheckAuthLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. }
  20. }
  21. func (l *CheckAuthLogic) CheckAuth(req *types.CheckAuthReq) (resp *types.AuthResp, err error) {
  22. if authResp, err := l.svcCtx.AuthRpc.CheckAuth(l.ctx, &pb.CheckAuthReq{
  23. AccessToken: req.AccessToken,
  24. }); err != nil {
  25. return &types.AuthResp{
  26. Code: authResp.Code,
  27. Msg: authResp.Msg,
  28. Data: map[string]interface{}{},
  29. }, err
  30. } else {
  31. return &types.AuthResp{
  32. Code: authResp.Code,
  33. Msg: authResp.Msg,
  34. Data: authResp.Data,
  35. }, nil
  36. }
  37. }