43 lines
844 B
Go
43 lines
844 B
Go
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
|
|
}
|