-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3ade83d
Showing
11 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
venv/ | ||
.flake8 | ||
.mypy_cache | ||
.envs | ||
|
||
.idea | ||
*.lock | ||
.DS_Store | ||
**/__pycache__/ | ||
.envs/ | ||
celery-beat-schedule | ||
celerybeat-schedule | ||
*.pid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
KEYCLOAK_SERVER_URL=https://sample.com | ||
KEYCLOAK_CLIENT_ID=sample | ||
KEYCLOAK_REALM_NAME=sample | ||
KEYCLOAK_CLIENT_SECRET=sample | ||
KEYCLOAK_ADMIN_CLIENT_SECRET=sample | ||
KEYCLOAK_CALLBACK_URI=http://sample.com/callback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Packages | ||
__pycache__ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
.venv/ | ||
venv/ | ||
.env | ||
|
||
# Python debug | ||
pdb/ | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery | ||
celerybeat-schedule* | ||
celerybeat.pid | ||
|
||
# Flask stuff | ||
instance/ | ||
.webassets-cache | ||
|
||
# Intellij IDEA specifics | ||
.idea/ | ||
.fleet/ | ||
|
||
# Qt related | ||
*.log | ||
*.log.* | ||
*.swo | ||
*.swp | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
+47 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
exclude: 'docs|node_modules|migrations|.git|.tox|.mypy_cache|frontend' | ||
default_stages: [commit] | ||
fail_fast: true | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: requirements-txt-fixer | ||
- id: check-merge-conflict | ||
- repo: https://github.com/myint/autoflake | ||
rev: v1.4 | ||
hooks: | ||
- id: autoflake | ||
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variables', '--ignore-init-module-imports'] | ||
- repo: https://github.com/psf/black | ||
rev: 23.11.0 | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/PyCQA/bandit | ||
rev: '1.7.5' | ||
hooks: | ||
- id: bandit |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from fastapi import APIRouter, Depends | ||
from fastapi_keycloak import OIDCUser | ||
|
||
from app.keycloak import idp | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/") | ||
def home(): | ||
"""Public home page.""" | ||
return {"message": "Hello World! This is a public endpoint"} | ||
|
||
|
||
@router.get("/me/") | ||
def my_user(user: OIDCUser = Depends(idp.get_current_user())): | ||
"""Shows the logged-in user's info. No specified role required.""" | ||
return user | ||
|
||
|
||
@router.get("/admin/") | ||
def my_admin(user: OIDCUser = Depends(idp.get_current_user(required_roles=["admin"]))): | ||
"""Endpoint specific for admins.""" | ||
return {"message": "Hello admin! This is an admin-only endpoint"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from fastapi import APIRouter | ||
|
||
from app import api | ||
|
||
api_router_v1 = APIRouter() | ||
api_router_v1.include_router(api.router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pydantic import BaseModel | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
|
||
class KeycloakSettings(BaseModel): | ||
server_url: str | ||
client_id: str | ||
client_secret: str | ||
realm_name: str | ||
admin_client_secret: str | ||
callback_uri: str | ||
|
||
|
||
class Settings(BaseSettings): | ||
model_config = SettingsConfigDict(env_file=".env", extra='ignore') | ||
|
||
keycloak_server_url: str | ||
keycloak_client_id: str | ||
keycloak_client_secret: str | ||
keycloak_realm_name: str | ||
keycloak_admin_client_secret: str | ||
keycloak_callback_uri: str | ||
|
||
|
||
settings = Settings() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from fastapi_keycloak import FastAPIKeycloak | ||
|
||
from app.config.base import settings | ||
|
||
idp = FastAPIKeycloak( | ||
server_url=settings.keycloak_server_url, | ||
client_id=settings.keycloak_client_id, | ||
client_secret=settings.keycloak_client_secret, | ||
admin_client_secret=settings.keycloak_admin_client_secret, | ||
realm=settings.keycloak_realm_name, | ||
callback_uri=settings.keycloak_callback_uri | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from fastapi import FastAPI | ||
|
||
from app.api.routers import api_router_v1 | ||
|
||
app = FastAPI() | ||
app.swagger_ui_init_oauth = { | ||
"usePkceWithAuthorizationCodeGrant": True, | ||
} | ||
|
||
app.include_router(api_router_v1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
annotated-types==0.6.0 | ||
anyio==4.2.0 | ||
asgiref==3.7.2 | ||
certifi==2023.11.17 | ||
cfgv==3.4.0 | ||
charset-normalizer==3.3.2 | ||
click==8.1.7 | ||
deprecation==2.1.0 | ||
distlib==0.3.8 | ||
ecdsa==0.18.0 | ||
fastapi==0.109.0 | ||
fastapi_keycloak==1.0.10 | ||
filelock==3.13.1 | ||
h11==0.14.0 | ||
httptools==0.6.1 | ||
identify==2.5.33 | ||
idna==3.6 | ||
itsdangerous==2.1.2 | ||
nodeenv==1.8.0 | ||
packaging==23.2 | ||
platformdirs==4.1.0 | ||
pre-commit==3.6.0 | ||
pyasn1==0.5.1 | ||
pydantic==2.5.3 | ||
pydantic-settings==2.1.0 | ||
pydantic_core==2.14.6 | ||
python-dotenv==1.0.0 | ||
python-jose==3.3.0 | ||
PyYAML==6.0.1 | ||
requests==2.31.0 | ||
requests-toolbelt==1.0.0 | ||
rsa==4.9 | ||
six==1.16.0 | ||
sniffio==1.3.0 | ||
starlette==0.35.1 | ||
typing_extensions==4.9.0 | ||
urllib3==2.1.0 | ||
uvicorn==0.26.0 | ||
uvloop==0.19.0 | ||
virtualenv==20.25.0 | ||
watchfiles==0.21.0 | ||
websockets==12.0 |