Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: add an example to illustrate authorization (authz) support #5920

Merged
merged 18 commits into from
Mar 2, 2023
Merged
15 changes: 15 additions & 0 deletions examples/features/authz/README.md
Expand Up @@ -7,10 +7,25 @@ be fetched from an appropriate service based on the authenticated context.

## Try it

Server requires the following roles on an authenticated user to authorise usage of these methods:
KenxinKun marked this conversation as resolved.
Show resolved Hide resolved

- `UnaryEcho` requires the role `UNARY_ECHO:W`
- `BidirectionalStreamingEcho` requires the role `STREAM_ECHO:RW`

Upon receiving a request, the server first checks that a token was supplied, decodes it and checks that a secret is correctly set (hardcoded to `super-secret` for simplicity, this should use a proper ID provider in production).
KenxinKun marked this conversation as resolved.
Show resolved Hide resolved

If the above is successful, it uses the username in the token to set appropriate roles (hardcoded to the 2 required roles above if the username matches `super-user` for simplicity, these roles should be supplied externally as well).

Start the server with:

```
go run server/main.go
```

The client implementation shows how using a valid token (setting username and secret) with each of the endpoints will return successfully. It also exemplifies how using a bad token will result in `codes.PermissionDenied` being returned from the service.

Start the client with:

```
go run client/main.go
dfawley marked this conversation as resolved.
Show resolved Hide resolved
```