WIP: Add test url

This commit is contained in:
Christian Cueni 2022-08-15 11:42:34 +02:00
parent cd829a3c9a
commit b06db37d05
3 changed files with 8 additions and 2 deletions

View File

@ -522,8 +522,8 @@ OAUTH = {
"client_name": env("IT_OAUTH_CLIENT_NAME", default="lernetz"), "client_name": env("IT_OAUTH_CLIENT_NAME", default="lernetz"),
"client_id": env("IT_OAUTH_CLIENT_ID", default="iterativ"), "client_id": env("IT_OAUTH_CLIENT_ID", default="iterativ"),
"client_secret": env("IT_OAUTH_CLIENT_SECRET", default=""), "client_secret": env("IT_OAUTH_CLIENT_SECRET", default=""),
"access_token_url": env("IT_OAUTH_ACCESS_TOKEN_URL", default="https://sso.test.b.lernetz.host/auth/realms/vbv/protocol/openid-connect/token"), # "access_token_url": env("IT_OAUTH_ACCESS_TOKEN_URL", default="https://sso.test.b.lernetz.host/auth/realms/vbv/protocol/openid-connect/token"),
"authorize_url": env("IT_OAUTH_AUTHORIZE_URL", default="https://sso.test.b.lernetz.host/auth/realms/vbv/protocol/openid-connect/auth"), # "authorize_url": env("IT_OAUTH_AUTHORIZE_URL", default="https://sso.test.b.lernetz.host/auth/realms/vbv/protocol/openid-connect/auth"),
"authorize_params": IT_OAUTH_AUTHORIZE_PARAMS, "authorize_params": IT_OAUTH_AUTHORIZE_PARAMS,
"access_token_params": IT_OAUTH_AUTHORIZE_PARAMS, "access_token_params": IT_OAUTH_AUTHORIZE_PARAMS,
"api_base_url": env("IT_OAUTH_API_BASE_URL", default="https://sso.test.b.lernetz.host/auth/realms/vbv/protocol/openid-connect/"), "api_base_url": env("IT_OAUTH_API_BASE_URL", default="https://sso.test.b.lernetz.host/auth/realms/vbv/protocol/openid-connect/"),

View File

@ -7,4 +7,5 @@ app_name = 'sso'
urlpatterns = [ urlpatterns = [
path(r'login/', django_view_authentication_exempt(views.login), name='login'), path(r'login/', django_view_authentication_exempt(views.login), name='login'),
path(r'callback/', django_view_authentication_exempt(views.authorize), name='authorize'), path(r'callback/', django_view_authentication_exempt(views.authorize), name='authorize'),
path(r'foo/', django_view_authentication_exempt(views.foo), name='foo'),
] ]

View File

@ -2,6 +2,7 @@ import structlog as structlog
from authlib.integrations.base_client import OAuthError from authlib.integrations.base_client import OAuthError
from django.conf import settings from django.conf import settings
from django.shortcuts import redirect from django.shortcuts import redirect
from django.http import HttpResponse
from sentry_sdk import capture_exception from sentry_sdk import capture_exception
from django.contrib.auth import login as dj_login, get_user_model from django.contrib.auth import login as dj_login, get_user_model
@ -40,6 +41,10 @@ def authorize(request):
return redirect(f'/{OAUTH_SUCCESS_REDIRECT}?state=success') # to be defined return redirect(f'/{OAUTH_SUCCESS_REDIRECT}?state=success') # to be defined
def foo(request):
return HttpResponse(settings.OAUTH["server_metadata_url"])
def _user_data_from_token_data(token: dict) -> dict: def _user_data_from_token_data(token: dict) -> dict:
return { return {
"first_name": token.get("given_name", ""), "first_name": token.get("given_name", ""),