disable login endpoint as wel

This commit is contained in:
Georges-Antoine Assi
2025-01-07 17:28:13 -05:00
parent bd51affb7c
commit 04c31374af
3 changed files with 53 additions and 45 deletions

View File

@@ -1,7 +1,7 @@
from datetime import datetime, timedelta, timezone
from typing import Annotated, Final
from config import OIDC_ENABLED, OIDC_REDIRECT_URI
from config import DISABLE_USERPASS_LOGIN, OIDC_ENABLED, OIDC_REDIRECT_URI
from decorators.auth import oauth
from endpoints.forms.identity import OAuth2RequestForm
from endpoints.responses import MessageResponse
@@ -11,6 +11,7 @@ from exceptions.auth_exceptions import (
OIDCDisabledException,
OIDCNotConfiguredException,
UserDisabledException,
UserPassDisabledException,
)
from fastapi import Depends, HTTPException, Request, status
from fastapi.responses import RedirectResponse
@@ -45,6 +46,9 @@ def login(
MessageResponse: Standard message response
"""
if DISABLE_USERPASS_LOGIN:
raise UserPassDisabledException
user = auth_handler.authenticate_user(credentials.username, credentials.password)
if not user:
raise AuthCredentialsException

View File

@@ -1,5 +1,10 @@
from fastapi import HTTPException, status
UserPassDisabledException = HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Username/password authentication disabled",
)
AuthCredentialsException = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",

View File

@@ -74,10 +74,10 @@ async function loginOIDC() {
<template>
<v-card class="translucent-dark py-8 px-5" width="500">
<v-img src="/assets/isotipo.svg" class="mx-auto" width="150" />
<v-img src="/assets/isotipo.svg" class="mx-auto mb-4" width="150" />
<v-row class="text-white justify-center mt-2" no-gutters>
<v-col cols="10">
<v-form @submit.prevent="login">
<v-form v-if="!loginDisabled" @submit.prevent="login">
<v-text-field
v-model="username"
:label="t('login.username')"
@@ -99,7 +99,6 @@ async function loginOIDC() {
variant="underlined"
/>
<v-btn
v-if="!loginDisabled"
type="submit"
class="bg-terciary mt-4"
variant="text"
@@ -120,48 +119,48 @@ async function loginOIDC() {
/>
</template>
</v-btn>
<template v-if="oidcEnabled">
<v-divider v-if="!loginDisabled" class="my-4">
<template #default>
<span class="px-1">{{ t("login.or") }}</span>
</template>
</v-divider>
<v-btn
block
type="submit"
class="bg-terciary"
variant="text"
:disabled="loggingInOIDC || loggingIn"
:loading="loggingInOIDC"
@click="loginOIDC()"
>
<template v-if="oidcProvider" #prepend>
<v-icon size="20">
<v-img
:src="`/assets/dashboard-icons/${oidcProvider.toLowerCase()}.png`"
>
<template #error>
<v-icon size="20">mdi-key</v-icon>
</template>
</v-img>
</v-icon>
</template>
{{
t("login.login-oidc", {
oidc: oidcProvider || "OIDC",
})
}}
<template #loader>
<v-progress-circular
color="romm-accent-1"
:width="2"
:size="20"
indeterminate
/>
</template>
</v-btn>
</template>
</v-form>
<template v-if="oidcEnabled">
<v-divider v-if="!loginDisabled" class="my-4">
<template #default>
<span class="px-1">{{ t("login.or") }}</span>
</template>
</v-divider>
<v-btn
block
type="submit"
class="bg-terciary"
variant="text"
:disabled="loggingInOIDC || loggingIn"
:loading="loggingInOIDC"
@click="loginOIDC()"
>
<template v-if="oidcProvider" #prepend>
<v-icon size="20">
<v-img
:src="`/assets/dashboard-icons/${oidcProvider.toLowerCase()}.png`"
>
<template #error>
<v-icon size="20">mdi-key</v-icon>
</template>
</v-img>
</v-icon>
</template>
{{
t("login.login-oidc", {
oidc: oidcProvider || "OIDC",
})
}}
<template #loader>
<v-progress-circular
color="romm-accent-1"
:width="2"
:size="20"
indeterminate
/>
</template>
</v-btn>
</template>
</v-col>
</v-row>
</v-card>