Skip to content

Commit

Permalink
Expand readme example and fix link to license (#10)
Browse files Browse the repository at this point in the history
* Expand example

* Fix link to license
  • Loading branch information
disrupted authored Mar 4, 2024
1 parent 1999ab9 commit ecf55b7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ pip install keycloak-oauth[fastapi]
```

```python
from fastapi import FastAPI
from typing import Annotated
from fastapi import FastAPI, Request, Depends
from starlette.middleware.sessions import SessionMiddleware
from backend.settings import settings, BASE_URL, SECRET_KEY # secrets
from keycloak_oauth import KeycloakOAuth2
Expand All @@ -29,6 +30,13 @@ keycloak.setup_fastapi_routes()
app = FastAPI()
app.add_middleware(SessionMiddleware, secret_key=SECRET_KEY)
app.include_router(keycloak.router, prefix="/auth")

@app.get("/")
def index(
request: Request, user: Annotated[User, Depends(KeycloakOAuth2.get_user)]
):
"""Protected endpoint, will return 401 Unauthorized if not signed in."""
return f"Hello {user.name}"
```

We now expose the API endpoints for Keycloak:
Expand Down Expand Up @@ -65,6 +73,8 @@ admin = Admin(
auth_provider=KeycloakAuthProvider(keycloak),
middlewares=[Middleware(SessionMiddleware, secret_key=SECRET_KEY)],
)

admin.add_view(...)
```

## Development
Expand All @@ -79,4 +89,4 @@ We are happy if you want to contribute to this project. If you find any bugs or

## License

This project is licensed under the MIT license. Have a look at the [LICENSE](LICENSE.md) for more details.
This project is licensed under the MIT license. Have a look at the [LICENSE](LICENSE) for more details.

0 comments on commit ecf55b7

Please sign in to comment.