From 635818ccb612ffe02aac504c6b0f669d53795b12 Mon Sep 17 00:00:00 2001 From: JunXu01 Date: Sun, 17 Nov 2024 00:11:05 +0800 Subject: [PATCH 1/2] fix acedata login --- api/configs/feature/__init__.py | 10 ------- api/controllers/console/auth/oauth.py | 13 ++++----- api/libs/oauth.py | 2 +- web/yarn.lock | 41 +++++++-------------------- 4 files changed, 16 insertions(+), 50 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index 42d96e7e5cad6f..744472074e400e 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -459,16 +459,6 @@ class AuthConfig(BaseSettings): default="", ) - ACEDATA_CLIENT_ID: Optional[str] = Field( - description="AceData OAuth client ID", - default="", - ) - - ACEDATA_CLIENT_SECRET: Optional[str] = Field( - description="AceData OAuth client secret", - default="", - ) - GOOGLE_CLIENT_ID: Optional[str] = Field( description="Google OAuth client ID", default=None, diff --git a/api/controllers/console/auth/oauth.py b/api/controllers/console/auth/oauth.py index f454e027c68bbe..07b9a9d091d40b 100644 --- a/api/controllers/console/auth/oauth.py +++ b/api/controllers/console/auth/oauth.py @@ -42,14 +42,11 @@ def get_oauth_providers(): redirect_uri=dify_config.CONSOLE_API_URL + "/console/api/oauth/authorize/google", ) - if not dify_config.ACEDATA_CLIENT_ID or not dify_config.ACEDATA_CLIENT_SECRET: - acedata_oauth = None - else: - acedata_oauth = AceDataOAuth( - client_id=dify_config.ACEDATA_CLIENT_ID, - client_secret=dify_config.ACEDATA_CLIENT_SECRET, - redirect_uri=dify_config.CONSOLE_API_URL + "/console/api/oauth/authorize/acedata", - ) + acedata_oauth = AceDataOAuth( + client_id=None, + client_secret=None, + redirect_uri=dify_config.CONSOLE_API_URL + "/console/api/oauth/authorize/acedata", + ) OAUTH_PROVIDERS = {"github": github_oauth, "google": google_oauth, "acedata": acedata_oauth} diff --git a/api/libs/oauth.py b/api/libs/oauth.py index 5ac7a791be135d..f7cc23af5d3c47 100644 --- a/api/libs/oauth.py +++ b/api/libs/oauth.py @@ -142,7 +142,7 @@ def get_authorization_url(self, invite_token: Optional[str] = None): params = { "site" : "https://dify.acedata.cloud/", - "redirect" : "http://dify.acedata.cloud/console/api/oauth/authorize/acedata" + "redirect" : self.redirect_uri, } return f"https://auth.acedata.cloud/auth/login?{urllib.parse.urlencode(params)}" diff --git a/web/yarn.lock b/web/yarn.lock index c91b5496841df1..8eaeae0a2e4de6 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -5781,7 +5781,7 @@ elkjs@^0.9.0: elliptic@^6.5.3, elliptic@^6.5.5: version "6.6.0" - resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.6.0.tgz#5919ec723286c1edf28685aa89261d4761afa210" + resolved "https://registry.npmjs.org/elliptic/-/elliptic-6.6.0.tgz" integrity sha512-dpwoQcLc/2WLQvJvLRHKZ+f9FgOdjnq11rurqwekGQygGPsYSK29OMMD2WalatiqQ+XGFDglTNixpPfI+lpaAA== dependencies: bn.js "^4.11.9" @@ -6897,11 +6897,6 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@^2.3.2, fsevents@~2.3.2: - version "2.3.3" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" - integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== - function-bind@^1.1.1, function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz" @@ -12173,7 +12168,7 @@ string-length@^4.0.1: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +string-width@^4.1.0, string-width@^4.2.0: version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -12182,25 +12177,16 @@ string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" -string-width@^5.0.0: - version "5.1.2" - resolved "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz" - integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA== - dependencies: - eastasianwidth "^0.2.0" - emoji-regex "^9.2.2" - strip-ansi "^7.0.1" - -string-width@^5.0.1: - version "5.1.2" - resolved "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz" - integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA== +string-width@^4.2.3: + version "4.2.3" + resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== dependencies: - eastasianwidth "^0.2.0" - emoji-regex "^9.2.2" - strip-ansi "^7.0.1" + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" -string-width@^5.1.2: +string-width@^5.0.0, string-width@^5.0.1, string-width@^5.1.2: version "5.1.2" resolved "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz" integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA== @@ -12273,13 +12259,6 @@ strip-ansi@^6.0.0, strip-ansi@^6.0.1: dependencies: ansi-regex "^5.0.1" -strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1, strip-ansi@^7.1.0: version "7.1.0" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz" From d280741b5ca8a2afd87ab0a62180be551a3910e3 Mon Sep 17 00:00:00 2001 From: JunXu01 Date: Sun, 17 Nov 2024 00:12:42 +0800 Subject: [PATCH 2/2] fix acedata login --- api/controllers/console/auth/oauth.py | 4 ++-- api/libs/oauth.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/controllers/console/auth/oauth.py b/api/controllers/console/auth/oauth.py index 07b9a9d091d40b..ef072c2c5dea89 100644 --- a/api/controllers/console/auth/oauth.py +++ b/api/controllers/console/auth/oauth.py @@ -12,14 +12,14 @@ from events.tenant_event import tenant_was_created from extensions.ext_database import db from libs.helper import extract_remote_ip -from libs.oauth import GitHubOAuth, GoogleOAuth, OAuthUserInfo, AceDataOAuth +from libs.oauth import AceDataOAuth, GitHubOAuth, GoogleOAuth, OAuthUserInfo from models import Account from models.account import AccountStatus from services.account_service import AccountService, RegisterService, TenantService from services.errors.account import AccountNotFoundError from services.errors.workspace import WorkSpaceNotAllowedCreateError, WorkSpaceNotFoundError from services.feature_service import FeatureService -import json + from .. import api diff --git a/api/libs/oauth.py b/api/libs/oauth.py index f7cc23af5d3c47..722157d546da31 100644 --- a/api/libs/oauth.py +++ b/api/libs/oauth.py @@ -141,14 +141,14 @@ class AceDataOAuth(OAuth): def get_authorization_url(self, invite_token: Optional[str] = None): params = { - "site" : "https://dify.acedata.cloud/", - "redirect" : self.redirect_uri, + "site": "https://dify.acedata.cloud/", + "redirect": self.redirect_uri, } return f"https://auth.acedata.cloud/auth/login?{urllib.parse.urlencode(params)}" def get_access_token(self, code: str): data = { - "code" : code + "code": code } headers = {"Accept": "application/json"} response = requests.post(self._TOKEN_URL, data=data, headers=headers)