Documentation ¶
Index ¶
Constants ¶
const TokenLen = 32
Variables ¶
var ( ErrInvalidToken = errors.New("invalid token") ErrInvalidNamespace = errors.New("invalid namespace") )
Functions ¶
This section is empty.
Types ¶
type Mock ¶
Mock implementation of Service.
type Service ¶
type Service interface { GenerateAndSave(db prefixer.Prefixer, op Operation, resource string, lifetime time.Duration) (string, error) Validate(db prefixer.Prefixer, op Operation, resource, token string) error }
Service used to generate token to protect and authenticate an operation outside cozy.
This service is used to protect unauthenticated operation done oustide the stack. For example when we need to validate an email with an URL link. Without this random token inside the url anyone could validate the email for anyone as user come unauthenticated.
type TokenService ¶
type TokenService struct {
// contains filtered or unexported fields
}
TokenService is a Service implementation based on cache.Cache.
Note: Depending on the cache implementation setup the storage can be store in-memory a reboot would invalidate all the existing tokens.
This can be the case for the self-hosted stacks using cache.InMemory.
func NewService ¶
func NewService(cache cache.Cache) *TokenService
NewService instantiates a new [CacheService].
func (*TokenService) GenerateAndSave ¶
func (s *TokenService) GenerateAndSave(db prefixer.Prefixer, op Operation, resource string, lifetime time.Duration) (string, error)
GenerateAndSave generate a random token and save it into the storage for the specified duration.
Once the lifetime is expired, the token is deleted and will be never valid.
func (*TokenService) Validate ¶
Validate will validate that the user as a matching token.
If the token doesn't match any content or an expired content the error ErrInvalidToken is returned.