Skip to content

Commit

Permalink
Revert "feat: add oauth invite redict"
Browse files Browse the repository at this point in the history
This reverts commit c84f004.
  • Loading branch information
ZhouhaoJiang committed Sep 2, 2024
1 parent 50849e7 commit 53d83c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
14 changes: 2 additions & 12 deletions api/controllers/console/auth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ def get_oauth_providers():


class OAuthLogin(Resource):
def get(self, provider: str, invite_toke: Optional[str] = None):
def get(self, provider: str):
OAUTH_PROVIDERS = get_oauth_providers()
with current_app.app_context():
oauth_provider = OAUTH_PROVIDERS.get(provider)
print(vars(oauth_provider))
if not oauth_provider:
return {"error": "Invalid provider"}, 400

auth_url = oauth_provider.get_authorization_url(invite_toke)
auth_url = oauth_provider.get_authorization_url()
return redirect(auth_url)


Expand All @@ -64,23 +64,13 @@ def get(self, provider: str):
return {"error": "Invalid provider"}, 400

code = request.args.get("code")
state = request.args.get("state")
invite_token = None
if state:
invite_token = state

try:
token = oauth_provider.get_access_token(code)
user_info = oauth_provider.get_user_info(token)
except requests.exceptions.HTTPError as e:
logging.exception(f"An error occurred during the OAuth process with {provider}: {e.response.text}")
return {"error": "OAuth process failed"}, 400

if invite_token:
return redirect(
f"{dify_config.CONSOLE_WEB_URL}/invite-settings?invite_token={invite_token}"
)

try:
account = _generate_account(provider, user_info)
except services.errors.account.AccountNotFound as e:
Expand Down
9 changes: 2 additions & 7 deletions api/libs/oauth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import urllib.parse
from dataclasses import dataclass
from typing import Optional

import requests

Expand Down Expand Up @@ -41,14 +40,12 @@ class GitHubOAuth(OAuth):
_USER_INFO_URL = "https://api.github.com/user"
_EMAIL_INFO_URL = "https://api.github.com/user/emails"

def get_authorization_url(self, invite_token: Optional[str] = None):
def get_authorization_url(self):
params = {
"client_id": self.client_id,
"redirect_uri": self.redirect_uri,
"scope": "user:email", # Request only basic user information
}
if invite_token:
params["state"] = invite_token
return f"{self._AUTH_URL}?{urllib.parse.urlencode(params)}"

def get_access_token(self, code: str):
Expand Down Expand Up @@ -93,15 +90,13 @@ class GoogleOAuth(OAuth):
_TOKEN_URL = "https://oauth2.googleapis.com/token"
_USER_INFO_URL = "https://www.googleapis.com/oauth2/v3/userinfo"

def get_authorization_url(self, invite_token: Optional[str] = None):
def get_authorization_url(self):
params = {
"client_id": self.client_id,
"response_type": "code",
"redirect_uri": self.redirect_uri,
"scope": "openid email",
}
if invite_token:
params["state"] = invite_token
return f"{self._AUTH_URL}?{urllib.parse.urlencode(params)}"

def get_access_token(self, code: str):
Expand Down

0 comments on commit 53d83c4

Please sign in to comment.