Compare commits

..

3 Commits

Author SHA1 Message Date
0aaf99da97 Add jwks_uri and use username
All checks were successful
continuous-integration/drone/push Build is passing
2021-06-11 18:26:38 +02:00
f2593e209e Use matching identifiers 2021-06-11 18:15:50 +02:00
65475912c1 Use more specific URL for keycloak 2021-06-11 18:14:34 +02:00
2 changed files with 5 additions and 4 deletions

View File

@ -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)

View File

@ -3,6 +3,6 @@
<title>Home</title> <title>Home</title>
</head> </head>
<body> <body>
<p>Hello, {{ user }}</p> <p>Hello, {{ user.preferred_username }}</p>
</body> </body>
</html> </html>