more ldap migration

This commit is contained in:
TuxCoder 2022-06-18 19:35:05 +02:00
parent 927562fecb
commit c6042973fe
7 changed files with 55 additions and 31 deletions

View file

@ -11,7 +11,6 @@ import logging
import httpx
from ..model import User
from ..auth_providers import LdapAuthProvider
from ..hydra import hydra_service
from ory_hydra_client.api.admin import introspect_o_auth_2_token
from ory_hydra_client.models import GenericError
@ -37,7 +36,7 @@ def user_list() -> ResponseReturnValue:
return jsonify([
{'username': str(user.username), 'email': str(user.email)}
for user in User.query_().all()])
for user in User.query.all()])
@api_views.route('/introspect', methods=['POST'])
def introspect() -> ResponseReturnValue:
@ -66,7 +65,7 @@ def email_login() -> ResponseReturnValue:
if not request.is_json:
return jsonify({}), 400
req_payload = request.get_json()
logger.error(f'{req_payload}')
logger.debug(f'{req_payload}')
if not isinstance(req_payload, dict):
return 'bad request', 400
password = req_payload["password"]

View file

@ -147,6 +147,7 @@ async def login_auth() -> ResponseReturnValue:
if auth_provider.get_name() not in session['auth_providers'] and\
auth_provider.check_auth(user, form):
session['auth_providers'].append(auth_provider.get_name())
session.modified = True
if auth_provider.get_name() not in session['auth_providers']:
auth_forms[auth_provider.get_name()]=form

View file

@ -27,7 +27,7 @@ from ..model import db, User, SecurityUser, Totp, WebauthnCredential
from ..form.frontend import ClientCertForm, TOTPForm, \
TOTPDeleteForm, PasswordChangeForm, WebauthnRegisterForm
from ..form.base import ButtonForm
from ..auth_providers import LdapAuthProvider
from ..auth_providers import PasswordAuthProvider
from .auth import webauthn
from .oauth2 import redirect_login, oauth2
from ..hydra import hydra_service
@ -275,7 +275,7 @@ def password_change_post() -> ResponseReturnValue:
if form.validate():
password_old = str(form.data['password_old'])
password_new = str(form.data['password_new'])
if not LdapAuthProvider.check_auth_internal(
if not PasswordAuthProvider.check_auth_internal(
current_user, password_old):
return jsonify(
{'errors': {'password_old': 'Old Password is invalid'}})

View file

@ -28,8 +28,8 @@ def redirect_login() -> ResponseReturnValue:
session['next_url'] = request.path
redirect_uri = url_for('oauth2.authorized', _external=True)
response = oauth2.custom.authorize_redirect(redirect_uri)
#if isinstance(response, ResponseReturnValue):
# raise RuntimeError("invalid redirect")
if isinstance(response, Response):
raise RuntimeError("invalid redirect")
return response