Skip to content

Commit

Permalink
chore: update README (#30)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Here are some quick tips:
If this is your first time contributing, [read our Contributing
Guidelines](https://github.com/openfga/.github/blob/main/CONTRIBUTING.md)
to learn how to create an acceptable PR for this repo.
By submitting a PR to this repository, you agree to the terms within the
[OpenFGA Code of
Conduct](https://github.com/openfga/.github/blob/main/CODE_OF_CONDUCT.md)

If your PR is under active development, please submit it as a "draft".
Once it's ready, open it up for review.
-->

<!-- Provide a brief summary of the changes -->

## Description
<!-- Provide a detailed description of the changes -->

Updates the README to be consistent with our other repositories.

## Review Checklist
- [x] I have clicked on ["allow edits by
maintainers"](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork).
- [ ] I have added documentation for new/changed functionality in this
PR or in a PR to [openfga.dev](https://github.com/openfga/openfga.dev)
[Provide a link to any relevant PRs in the references section above]
- [x] The correct base branch is being used, if not `main`
- [ ] I have added tests to validate that the change in functionality is
working as expected
  • Loading branch information
jimmyjames authored Mar 21, 2024
2 parents 8ae436b + e217504 commit 2ea1529
Showing 1 changed file with 67 additions and 13 deletions.
80 changes: 67 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,75 @@
# OpenFGA Spring Boot Starter

[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](./LICENSE)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fopenfga%2Ffga-spring-boot.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fopenfga%2Ffga-spring-boot?ref=badge_shield)
[![Join our community](https://img.shields.io/badge/slack-cncf_%23openfga-40abb8.svg?logo=slack)](https://openfga.dev/community)
[![Twitter](https://img.shields.io/twitter/follow/openfga?color=%23179CF0&logo=twitter&style=flat-square "@openfga on Twitter")](https://twitter.com/openfga)

A Spring Boot Starter for OpenFGA.

## Configuration
## About

[OpenFGA](https://openfga.dev) is an open source Fine-Grained Authorization solution inspired by [Google's Zanzibar paper](https://research.google/pubs/pub48190/). It was created by the FGA team at [Auth0](https://auth0.com) based on [Auth0 Fine-Grained Authorization (FGA)](https://fga.dev), available under [a permissive license (Apache-2)](https://github.com/openfga/rfcs/blob/main/LICENSE) and welcomes community contributions.

OpenFGA is designed to make it easy for application builders to model their permission layer, and to add and integrate fine-grained authorization into their applications. OpenFGA’s design is optimized for reliability and low latency at a high scale.

## Resources

- [OpenFGA Documentation](https://openfga.dev/docs)
- [OpenFGA API Documentation](https://openfga.dev/api/service)
- [Twitter](https://twitter.com/openfga)
- [OpenFGA Community](https://openfga.dev/community)
- [Zanzibar Academy](https://zanzibar.academy)
- [Google's Zanzibar Paper (2019)](https://research.google/pubs/pub48190/)

## Getting Started

### Requirements

No authorization:
Java 17 and Spring Boot 3

### Configuring the starter

The OpenFGA Spring Boot Starter can be configured via standard [Spring configuration](https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config).
The configuration properties are used to create an [OpenFgaClient](https://github.com/openfga/java-sdk/blob/main/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java) instance.

#### No Credentials

```yaml
# src/main/resources/application.yaml

openfga:
api-url: YOUR_FGA_API_URL
store-id: YOUR_FGA_STORE_ID
authorization-model-id: YOUR_FGA_AUTHORIZATION_MODEL_ID
```
API token authorization:
#### API Token
```yaml
# src/main/resources/application.yaml

openfga:
api-url: YOUR_FGA_API_URL
store-id: YOUR_FGA_STORE_ID
authorization-model-id: YOUR_FGA_AUTHORIZATION_MODEL_ID
credentials:
method: API_TOKEN
method: API_TOKEN # constant
config:
api-token: YOUR_API_TOKEN
```
Client credentials authorization:
#### Client Credentials
```yaml
# src/main/resources/application.yaml

openfga:
api-url: YOUR_FGA_API_URL
store-id: YOUR_FGA_STORE_ID
authorization-model-id: YOUR_FGA_AUTHORIZATION_MODEL_ID
credentials:
method: CLIENT_CONFIGURATION
method: CLIENT_CONFIGURATION # constant
config:
client-id: YOUR_CLIENT_ID
client-secret: YOUR_CLIENT_SECRET
Expand All @@ -43,7 +78,9 @@ openfga:
scopes: YOUR_SPACE_SEPERATED_SCOPES
```
Your application can then inject the configured `fgaClient`:
### Using the `fgaClient` bean

Once configured, an `fgaClient` bean is available to be injected into your Spring components:

```java
@Service
Expand All @@ -54,9 +91,6 @@ public class MyService {
}
```

## Usage

Once configured, your application can inject the configured `fgaClient` bean into any component.
This can be used to interact with the FGA API, for example to write authorization data:

```java
Expand All @@ -65,7 +99,7 @@ public Document createDoc(String id) {
ClientWriteRequest writeRequest = new ClientWriteRequest()
.writes(List.of(new ClientTupleKey()
.user(String.format("user:%s", SecurityContextHolder.getContext().getAuthentication()))
.relation("reader")
.relation("owner")
._object(String.format("document:%s", id))));
try {
Expand All @@ -77,7 +111,9 @@ public Document createDoc(String id) {
}
```

This starter also creates an `fga` bean, which can be used in conjunction with Spring Security's method
### Using the `fga` bean

The starter also creates an `fga` bean, which can be used in conjunction with Spring Security's method
security to protect access to resources using FGA:

```java
Expand All @@ -88,7 +124,7 @@ public Document getDocument(@PathVariable String docId) {
}
```

You may also omit the user ID, in which case the name of the currently authenticated principal
You may also omit the user ID, in which case the name of the currently authenticated principal
will be used as the user ID:

```java
Expand All @@ -98,3 +134,21 @@ public Document getDocument(@PathVariable String docId) {
return repository.findById(id);
}
```

## Contributing

### Issues

If you have found a bug or if you have a feature request, please [create an issue](https://github.com/openfga/fga-spring-boot/issues). Please do not report security vulnerabilities on the public GitHub issue tracker.

### Pull Requests

Pull requests are welcome, however we do kindly ask that for non-trivial changes or feature additions, that you create an [issue]((https://github.com/openfga/fga-spring-boot/issues)) first.

## Author

[OpenFGA](https://github.com/openfga)

## License

This project is licensed under the Apache-2.0 license. See the [LICENSE](https://github.com/openfga/fga-spring-boot/blob/main/LICENSE) file for more info.

0 comments on commit 2ea1529

Please sign in to comment.