44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
# Copyright (c) 2019. Tobias Kurze
|
|
"""
|
|
Base module for auth aspects.
|
|
|
|
Also this module contains mainly code for login through HTML pages served by the backend.
|
|
If frontend pages are build by frontend code (JS, etc.) authentication should consider using api functions.
|
|
(For more info, see api.auth_api.py.)
|
|
"""
|
|
from flask import Blueprint
|
|
from werkzeug.routing import BuildError
|
|
|
|
auth_bp = Blueprint('auth', __name__, url_prefix='/auth', template_folder='templates')
|
|
|
|
from backend.auth.config import AUTH_PROVIDERS, DEFAULT_PROVIDER
|
|
from backend.auth.oidc_config import OIDC_PROVIDERS
|
|
|
|
from backend.auth.oidc import oidc_auth
|
|
|
|
from .basic_auth import *
|
|
|
|
|
|
def auth_decorator(): # custom decorator
|
|
pass
|
|
|
|
|
|
@auth_bp.route('/login', methods=['GET', 'POST'])
|
|
def login():
|
|
try:
|
|
prov = AUTH_PROVIDERS[DEFAULT_PROVIDER]
|
|
except KeyError:
|
|
return "No known default provider specified!"
|
|
url = prov["url"]
|
|
try:
|
|
url = url_for(prov["url"], next=request.endpoint)
|
|
except BuildError as e:
|
|
pass
|
|
#logger.log("Can't create endpoint for '{}' (specified provider: {}).".format(e.endpoint, DEFAULT_PROVIDER))
|
|
return redirect(url)
|
|
|
|
|
|
@auth_bp.route('/login_select', methods=['GET'])
|
|
def login_select():
|
|
return render_template('login_select.html', providers=AUTH_PROVIDERS)
|