-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ce2d20
commit 4c882cc
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
## Project goals | ||
|
||
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. | ||
|
||
## Usage | ||
|
||
### Retrieve token | ||
|
||
#### gRPC Context | ||
|
||
```go | ||
// context metadata => Authorization: Bearer ... | ||
|
||
token, err := visiauth.RetrieveTokenFromContext(ctx) | ||
if err != nil { | ||
... | ||
} | ||
``` | ||
|
||
#### HTTP Request | ||
|
||
```go | ||
// request header => Authorization: Bearer ... | ||
|
||
token, err := visiauth.RetrieveTokenFromRequest(req) | ||
if err != nil { | ||
... | ||
} | ||
``` | ||
|
||
#### PubSub message attribute | ||
|
||
```go | ||
// message attribute => Authorization: Bearer ... | ||
|
||
token, err := visiauth.RetrieveTokenFromPubSubMessageAttribute(req) | ||
if err != nil { | ||
... | ||
} | ||
``` | ||
|
||
### Decode token | ||
|
||
```go | ||
service := visiauth.NewService(redis.NewJwkFetcher(), neo4j.NewUserRepository()) | ||
|
||
identity, err = service.DecodeAccessToken(r.Context(), token) | ||
if err != nil { | ||
... | ||
} | ||
``` | ||
|
||
## Identities | ||
|
||
Two types of identities are provided by service : User and Application. | ||
|
||
### User access token (User) | ||
|
||
If token was generated using Client credentials flow, identity will be a user. | ||
|
||
```go | ||
user, ok := identity.(*visiauth.User) | ||
if !ok { | ||
... | ||
} | ||
``` | ||
|
||
### M2M Token (Application) | ||
|
||
If token was generated using Client ID and Client secret, identity will be an application. | ||
|
||
```go | ||
app, ok := identity.(*visiauth.App) | ||
if !ok { | ||
... | ||
} | ||
``` | ||
|