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

Expand readme example and fix link to license #10

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading