This package provides functions and service to help you making authentication verifications. You can retrieve and decode bearer tokens, such as User access token or M2M token.
// context metadata => Authorization: Bearer ...
token, err := visiauth.RetrieveTokenFromContext(ctx)
if err != nil {
...
}
// request header => Authorization: Bearer ...
token, err := visiauth.RetrieveTokenFromRequest(req)
if err != nil {
...
}
// message attribute => Authorization: Bearer ...
token, err := visiauth.RetrieveTokenFromPubSubMessageAttribute(req)
if err != nil {
...
}
service := visiauth.NewService(redis.NewJwkFetcher(), neo4j.NewUserRepository())
identity, err = service.DecodeAccessToken(r.Context(), token)
if err != nil {
...
}
Two types of identities are provided by service : User and Application.
If token was generated using Client credentials flow, identity will be a user.
user, ok := identity.(*visiauth.User)
if !ok {
...
}
If token was generated using Client ID and Client secret, identity will be an application.
app, ok := identity.(*visiauth.App)
if !ok {
...
}
Some environment vars are required to use visiauth
.
Only vars of imported subpackages must be set.
- VISIAUTH_REDIS_ADDR
- VISIAUTH_REDIS_USER
- VISIAUTH_REDIS_PASSWORD
- VISIAUTH_AUTH0_DOMAIN
- VISIAUTH_NEO4J_USER
- VISIAUTH_NEO4J_URI
- VISIAUTH_NEO4J_PASSWORD