|
|
@ -26,6 +26,7 @@ oauth.register(
|
|
|
|
client_secret=KEYCLOAK_CLIENT_SECRET,
|
|
|
|
client_secret=KEYCLOAK_CLIENT_SECRET,
|
|
|
|
authorize_url=f"https://{KEYCLOAK_DOMAIN}/auth/realms/{KEYCLOAK_REALM}/protocol/openid-connect/auth",
|
|
|
|
authorize_url=f"https://{KEYCLOAK_DOMAIN}/auth/realms/{KEYCLOAK_REALM}/protocol/openid-connect/auth",
|
|
|
|
access_token_url=f"https://{KEYCLOAK_DOMAIN}/auth/realms/{KEYCLOAK_REALM}/protocol/openid-connect/token",
|
|
|
|
access_token_url=f"https://{KEYCLOAK_DOMAIN}/auth/realms/{KEYCLOAK_REALM}/protocol/openid-connect/token",
|
|
|
|
|
|
|
|
jwks_uri=f"https://{KEYCLOAK_DOMAIN}/auth/realms/{KEYCLOAK_REALM}/protocol/openid-connect/certs",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -41,12 +42,12 @@ async def home(request: Request):
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/login/keycloak")
|
|
|
|
@app.get("/login/keycloak")
|
|
|
|
async def login_keycloak(request: Request):
|
|
|
|
async def login_keycloak(request: Request):
|
|
|
|
redirect_uri = request.url_for("auth")
|
|
|
|
redirect_uri = request.url_for("auth_keycloak")
|
|
|
|
return await oauth.keycloak.authorize_redirect(request, redirect_uri)
|
|
|
|
return await oauth.keycloak.authorize_redirect(request, redirect_uri)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/auth")
|
|
|
|
@app.get("/auth/keycloak")
|
|
|
|
async def auth(request: Request):
|
|
|
|
async def auth_keycloak(request: Request):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
token = await oauth.keycloak.authorize_access_token(request)
|
|
|
|
token = await oauth.keycloak.authorize_access_token(request)
|
|
|
|
user = await oauth.keycloak.parse_id_token(request, token)
|
|
|
|
user = await oauth.keycloak.parse_id_token(request, token)
|
|
|
|