diff --git a/backend/open_webui/apps/webui/routers/auths.py b/backend/open_webui/apps/webui/routers/auths.py index 63ee5e3b0..9c0a6e452 100644 --- a/backend/open_webui/apps/webui/routers/auths.py +++ b/backend/open_webui/apps/webui/routers/auths.py @@ -238,10 +238,20 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): user = Users.get_user_by_email(mail) if not user: - try: - hashed = get_password_hash(form_data.password) - user = Auths.insert_new_auth(mail, hashed, cn) + role = ( + "admin" + if Users.get_num_users() == 0 + else request.app.state.config.DEFAULT_USER_ROLE + ) + + user = Auths.insert_new_auth( + mail, + str(uuid.uuid4()), + cn, + None, + role, + ) if not user: raise HTTPException( @@ -253,7 +263,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): except Exception as err: raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err)) - user = Auths.authenticate_user(mail, password=str(form_data.password)) + user = Auths.authenticate_user_by_trusted_header(mail) if user: token = create_token( diff --git a/src/routes/auth/+page.svelte b/src/routes/auth/+page.svelte index f40307816..2148061e7 100644 --- a/src/routes/auth/+page.svelte +++ b/src/routes/auth/+page.svelte @@ -203,7 +203,7 @@ {/if} - {#if $config?.features.enable_login_form} + {#if $config?.features.enable_login_form || $config?.features.enable_ldap}