mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 04:25:42 +00:00
switch to browser based sessions
This commit is contained in:
@ -5,6 +5,7 @@ import datetime
|
|||||||
from django.contrib.auth import get_user, login
|
from django.contrib.auth import get_user, login
|
||||||
from django.contrib.auth.models import Group, User
|
from django.contrib.auth.models import Group, User
|
||||||
from django.urls import include, path, re_path
|
from django.urls import include, path, re_path
|
||||||
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||||
from django.views.generic.base import RedirectView
|
from django.views.generic.base import RedirectView
|
||||||
|
|
||||||
import structlog
|
import structlog
|
||||||
@ -330,7 +331,7 @@ class LoginRedirect(RedirectView):
|
|||||||
|
|
||||||
user_urls = [
|
user_urls = [
|
||||||
path('roles/', RoleDetails.as_view(), name='api-user-roles'),
|
path('roles/', RoleDetails.as_view(), name='api-user-roles'),
|
||||||
path('token/', GetAuthToken.as_view(), name='api-token'),
|
path('token/', ensure_csrf_cookie(GetAuthToken.as_view()), name='api-token'),
|
||||||
path(
|
path(
|
||||||
'tokens/',
|
'tokens/',
|
||||||
include([
|
include([
|
||||||
|
@ -19,13 +19,13 @@ export enum ApiEndpoints {
|
|||||||
user_reset = 'auth/password/reset/',
|
user_reset = 'auth/password/reset/',
|
||||||
user_reset_set = 'auth/password/reset/confirm/',
|
user_reset_set = 'auth/password/reset/confirm/',
|
||||||
user_change_password = 'auth/password/change/',
|
user_change_password = 'auth/password/change/',
|
||||||
user_sso = '_allauth/app/v1/account/providers',
|
user_sso = '_allauth/browser/v1/account/providers',
|
||||||
user_login = '_allauth/app/v1/auth/login',
|
user_login = '_allauth/browser/v1/auth/login',
|
||||||
user_login_mfa = '_allauth/app/v1/auth/2fa/authenticate',
|
user_login_mfa = '_allauth/browser/v1/auth/2fa/authenticate',
|
||||||
user_logout = '_allauth/app/v1/auth/session',
|
user_logout = '_allauth/browser/v1/auth/session',
|
||||||
user_register = 'auth/registration/',
|
user_register = 'auth/registration/',
|
||||||
user_mfa = '_allauth/app/v1/account/authenticators',
|
user_mfa = '_allauth/browser/v1/account/authenticators',
|
||||||
user_emails = '_allauth/app/v1/account/email',
|
user_emails = '_allauth/browser/v1/account/email',
|
||||||
login_provider_redirect = '_allauth/browser/v1/auth/provider/redirect',
|
login_provider_redirect = '_allauth/browser/v1/auth/provider/redirect',
|
||||||
|
|
||||||
// Generic API endpoints
|
// Generic API endpoints
|
||||||
|
@ -73,9 +73,16 @@ export const doBasicLogin = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
clearCsrfCookie();
|
clearCsrfCookie();
|
||||||
|
const cookie = getCsrfCookie();
|
||||||
|
|
||||||
const login_url = apiUrl(ApiEndpoints.user_login);
|
const login_url = apiUrl(ApiEndpoints.user_login);
|
||||||
|
|
||||||
|
if (cookie == undefined) {
|
||||||
|
await api.get(apiUrl(ApiEndpoints.user_token)).catch(() => {
|
||||||
|
// his is to be expected
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let loginDone = false;
|
let loginDone = false;
|
||||||
let success = false;
|
let success = false;
|
||||||
|
|
||||||
@ -115,7 +122,7 @@ export const doBasicLogin = async (
|
|||||||
if (loginDone) {
|
if (loginDone) {
|
||||||
await fetchUserState();
|
await fetchUserState();
|
||||||
fetchGlobalStates();
|
fetchGlobalStates();
|
||||||
} else {
|
} else if (!success) {
|
||||||
clearUserState();
|
clearUserState();
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
|
Reference in New Issue
Block a user