mirror of
https://github.com/langgenius/dify.git
synced 2025-12-20 14:42:37 +00:00
Compare commits
3 Commits
feat/fallb
...
fix/login-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f241a6d83b | ||
|
|
96d7127d9c | ||
|
|
63eba34af7 |
@@ -1,6 +1,7 @@
|
|||||||
import flask_login
|
import flask_login
|
||||||
from flask import make_response, request
|
from flask import make_response, request
|
||||||
from flask_restx import Resource, reqparse
|
from flask_restx import Resource, reqparse
|
||||||
|
from werkzeug.exceptions import Unauthorized
|
||||||
|
|
||||||
import services
|
import services
|
||||||
from configs import dify_config
|
from configs import dify_config
|
||||||
@@ -25,7 +26,9 @@ from controllers.console.wraps import email_password_login_enabled, setup_requir
|
|||||||
from events.tenant_event import tenant_was_created
|
from events.tenant_event import tenant_was_created
|
||||||
from libs.helper import email, extract_remote_ip
|
from libs.helper import email, extract_remote_ip
|
||||||
from libs.login import current_account_with_tenant
|
from libs.login import current_account_with_tenant
|
||||||
|
from libs.passport import PassportService
|
||||||
from libs.token import (
|
from libs.token import (
|
||||||
|
check_csrf_token,
|
||||||
clear_access_token_from_cookie,
|
clear_access_token_from_cookie,
|
||||||
clear_csrf_token_from_cookie,
|
clear_csrf_token_from_cookie,
|
||||||
clear_refresh_token_from_cookie,
|
clear_refresh_token_from_cookie,
|
||||||
@@ -295,4 +298,12 @@ class LoginStatus(Resource):
|
|||||||
def get(self):
|
def get(self):
|
||||||
token = extract_access_token(request)
|
token = extract_access_token(request)
|
||||||
csrf_token = extract_csrf_token(request)
|
csrf_token = extract_csrf_token(request)
|
||||||
return {"logged_in": bool(token) and bool(csrf_token)}
|
if not token or not csrf_token:
|
||||||
|
return {"logged_in": False}
|
||||||
|
res = True
|
||||||
|
try:
|
||||||
|
validated = PassportService().verify(token=token)
|
||||||
|
check_csrf_token(request=request, user_id=validated.get("user_id", ""))
|
||||||
|
except Unauthorized:
|
||||||
|
res = False
|
||||||
|
return {"logged_in": res}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
import jwt
|
import jwt
|
||||||
from werkzeug.exceptions import Unauthorized
|
from werkzeug.exceptions import Unauthorized
|
||||||
|
|
||||||
@@ -11,7 +13,7 @@ class PassportService:
|
|||||||
def issue(self, payload):
|
def issue(self, payload):
|
||||||
return jwt.encode(payload, self.sk, algorithm="HS256")
|
return jwt.encode(payload, self.sk, algorithm="HS256")
|
||||||
|
|
||||||
def verify(self, token):
|
def verify(self, token) -> dict[str, Any]:
|
||||||
try:
|
try:
|
||||||
return jwt.decode(token, self.sk, algorithms=["HS256"])
|
return jwt.decode(token, self.sk, algorithms=["HS256"])
|
||||||
except jwt.ExpiredSignatureError:
|
except jwt.ExpiredSignatureError:
|
||||||
|
|||||||
Reference in New Issue
Block a user