mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
feat: web sso app
This commit is contained in:
parent
f0d10553b4
commit
425f8710c4
|
@ -17,6 +17,7 @@ from fields.app_fields import (
|
|||
from libs.login import login_required
|
||||
from services.app_dsl_service import AppDslService
|
||||
from services.app_service import AppService
|
||||
from services.feature_service import FeatureService
|
||||
|
||||
ALLOW_CREATE_APP_MODES = ['chat', 'agent-chat', 'advanced-chat', 'workflow', 'completion']
|
||||
|
||||
|
@ -362,6 +363,32 @@ class AppTraceApi(Resource):
|
|||
return {"result": "success"}
|
||||
|
||||
|
||||
class AppSSOApi(Resource):
|
||||
|
||||
@setup_required
|
||||
@login_required
|
||||
@account_initialization_required
|
||||
def get(self):
|
||||
return FeatureService.get_system_features().model_dump()
|
||||
|
||||
@setup_required
|
||||
@login_required
|
||||
@account_initialization_required
|
||||
def patch(self):
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('exclude_app_id_list', type=list, location='json')
|
||||
|
||||
if not current_user.is_editor:
|
||||
raise Forbidden()
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
current_user_id = current_user.id
|
||||
FeatureService.update_web_sso_exclude_apps(args['exclude_app_id_list'], current_user_id)
|
||||
|
||||
return {"result": "success"}
|
||||
|
||||
|
||||
api.add_resource(AppListApi, '/apps')
|
||||
api.add_resource(AppImportApi, '/apps/import')
|
||||
api.add_resource(AppImportFromUrlApi, '/apps/import/url')
|
||||
|
@ -373,3 +400,4 @@ api.add_resource(AppIconApi, '/apps/<uuid:app_id>/icon')
|
|||
api.add_resource(AppSiteStatus, '/apps/<uuid:app_id>/site-enable')
|
||||
api.add_resource(AppApiStatus, '/apps/<uuid:app_id>/api-enable')
|
||||
api.add_resource(AppTraceApi, '/apps/<uuid:app_id>/trace')
|
||||
api.add_resource(AppSSOApi, '/apps/web-sso')
|
||||
|
|
|
@ -14,10 +14,12 @@ from services.feature_service import FeatureService
|
|||
|
||||
class PassportResource(Resource):
|
||||
"""Base resource for passport."""
|
||||
def get(self):
|
||||
|
||||
def get(self, app_id):
|
||||
system_features = FeatureService.get_system_features()
|
||||
if system_features.sso_enforced_for_web:
|
||||
web_sso_exclude_apps = system_features.sso_exclude_apps
|
||||
|
||||
if system_features.sso_enforced_for_web and app_id not in web_sso_exclude_apps:
|
||||
raise WebSSOAuthRequiredError()
|
||||
|
||||
app_code = request.headers.get('X-App-Code')
|
||||
|
|
|
@ -5,4 +5,10 @@ class EnterpriseService:
|
|||
|
||||
@classmethod
|
||||
def get_info(cls):
|
||||
return EnterpriseRequest.send_request('GET', '/info')
|
||||
return EnterpriseRequest.send_request("GET", "/inner/api/info")
|
||||
|
||||
@classmethod
|
||||
def update_web_sso_exclude_apps(cls, app_id_list, user_id):
|
||||
return EnterpriseRequest.send_request(
|
||||
"PATCH", "/inner/api/web-sso-exclude-apps", json={"app_id_list": app_id_list, "user_id": user_id}
|
||||
)
|
||||
|
|
|
@ -41,6 +41,7 @@ class SystemFeatureModel(BaseModel):
|
|||
sso_enforced_for_signin_protocol: str = ''
|
||||
sso_enforced_for_web: bool = False
|
||||
sso_enforced_for_web_protocol: str = ''
|
||||
sso_exclude_apps: list = []
|
||||
|
||||
|
||||
class FeatureService:
|
||||
|
@ -116,3 +117,9 @@ class FeatureService:
|
|||
features.sso_enforced_for_signin_protocol = enterprise_info['sso_enforced_for_signin_protocol']
|
||||
features.sso_enforced_for_web = enterprise_info['sso_enforced_for_web']
|
||||
features.sso_enforced_for_web_protocol = enterprise_info['sso_enforced_for_web_protocol']
|
||||
features.sso_exclude_apps = enterprise_info['sso_exclude_apps']
|
||||
|
||||
@classmethod
|
||||
def update_web_sso_exclude_apps(cls, app_id_list, user_id):
|
||||
EnterpriseService.update_web_sso_exclude_apps(app_id_list, user_id)
|
||||
return True
|
||||
|
|
Loading…
Reference in New Issue
Block a user