github.com/aacfactory/fns@v1.2.86-0.20240310083819-80d667fc0a17/docs/authorizations.md (about) 1 # Authorizations 2 3 --- 4 5 The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a protected resource. 6 Read [Authorization](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization) for more. 7 8 ## Components 9 ### Encoding 10 `DEFAULT` encoding is builtin `fns`, config is 11 ```yaml 12 authorizations: 13 encoding: 14 expireMinutes: 1440 15 ``` 16 `JWT` encoding is supplied by `fns-contrib`, read [doc](https://github.com/aacfactory/fns-contrib/tree/main/authorizations/encoding/jwt) for more. 17 ### Store 18 `Discard` store is not persistence user tokens, so `revoke` api is not responded. 19 20 `Redis`, `Postgres` and `MYSQL` are supplied by `fns-contrib`, read [doc](https://github.com/aacfactory/fns-contrib/tree/main/authorizations/store) for more. 21 22 ## API 23 Encoding, it will return a token. 24 ```go 25 token, encodingErr := authorizations.Encode(ctx, "userId", userAttributes) 26 ``` 27 Verify current user token in request context, if `@authorization` is true, it will be auto invoked. 28 ```go 29 verifyErr := authorizations.Verify(ctx) 30 ``` 31 Revoke token. 32 ```go 33 revokeErr := authorizations.Revoke(ctx, "tokenId") 34 ``` 35 Revoke user tokens. 36 ```go 37 revokeErr := authorizations.RevokeUserTokens(ctx, "userId") 38 ```