auth provider
This commit is contained in:
parent
08d8450dac
commit
a66873d12d
6 changed files with 432 additions and 0 deletions
43
pkg/authCheck/service.go
Normal file
43
pkg/authCheck/service.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package authCheck
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
verifyV1 "merch-api/pkg/verify/v1"
|
||||
"time"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
client verifyV1.AuthServiceClient
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func newService(c verifyV1.AuthServiceClient, timeout time.Duration) *service {
|
||||
return &service{
|
||||
client: c,
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *service) VerifySession(ctx context.Context, sessionUuid string, serviceId int32) (string, error) {
|
||||
runCtx, cancel := context.WithTimeout(ctx, s.timeout)
|
||||
defer cancel()
|
||||
|
||||
response, err := s.client.VerifyToken(runCtx, &verifyV1.VerifyTokenRequest{
|
||||
SessionToken: sessionUuid,
|
||||
ServiceId: serviceId,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if response == nil {
|
||||
return "", errors.New("no token")
|
||||
}
|
||||
|
||||
if response.IsValid != true {
|
||||
return "", errors.New("invalid token")
|
||||
}
|
||||
|
||||
return response.UserUuid, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue