34 lines
967 B
Python
34 lines
967 B
Python
import logging
|
|
from authlib.integrations.base_client import OAuthError
|
|
from django.conf import settings
|
|
from django.shortcuts import redirect
|
|
from sentry_sdk import capture_exception
|
|
from django.contrib.auth import login as dj_login
|
|
|
|
from vbv_lernwelt.sso.client import oauth
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
OAUTH_REDIRECT = 'oauth-redirect'
|
|
|
|
|
|
def login(request):
|
|
oauth_client = oauth.create_client(settings.OAUTH["client_name"])
|
|
redirect_uri = settings.OAUTH["local_redirect_uri"]
|
|
return oauth_client.authorize_redirect(request, redirect_uri)
|
|
|
|
|
|
def authorize(request):
|
|
try:
|
|
logger.debug(request)
|
|
token = oauth.lernetz.authorize_access_token(request)
|
|
print(token)
|
|
except OAuthError as e:
|
|
logger.warning(f'OAuth error: {e}')
|
|
if not settings.DEBUG:
|
|
capture_exception(e)
|
|
return redirect(f'/{OAUTH_REDIRECT}?state=someerror')
|
|
|
|
|
|
return redirect(f'/{OAUTH_REDIRECT}?state=success')
|