From 56030b1c2cb9db9619602264e744bdb70fe11ea6 Mon Sep 17 00:00:00 2001 From: venplane <118932524+venplane@users.noreply.github.com> Date: Thu, 9 Feb 2023 00:01:45 +0530 Subject: [PATCH] fix: github auth login (#250) * fix: added PROJECT_ISSUES_LIST on the imports (#221) * fix: github signin by parsing email * refactor: changed variable names --------- Co-authored-by: sriram veeraghanta Co-authored-by: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Co-authored-by: Vamsi Kurama --- apiserver/plane/api/views/oauth.py | 18 +++++--- .../account/github-login-button.tsx | 2 +- apps/app/pages/signin.tsx | 43 ++++++++++--------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/apiserver/plane/api/views/oauth.py b/apiserver/plane/api/views/oauth.py index bcebfb29436..994cb0466ab 100644 --- a/apiserver/plane/api/views/oauth.py +++ b/apiserver/plane/api/views/oauth.py @@ -34,7 +34,6 @@ def get_tokens_for_user(user): def validate_google_token(token, client_id): try: - id_info = id_token.verify_oauth2_token( token, google_auth_request.Request(), client_id ) @@ -106,9 +105,19 @@ def get_user_data(access_token: str) -> dict: resp = requests.get(url=url, headers=headers) - userData = resp.json() + user_data = resp.json() + + response = requests.get( + url="https://api.github.com/user/emails", headers=headers + ).json() + + [ + user_data.update({"email": item.get("email")}) + for item in response + if item.get("primary") is True + ] - return userData + return user_data class OauthEndpoint(BaseAPIView): @@ -116,7 +125,6 @@ class OauthEndpoint(BaseAPIView): def post(self, request): try: - medium = request.data.get("medium", False) id_token = request.data.get("credential", False) client_id = request.data.get("clientId", False) @@ -138,7 +146,6 @@ def post(self, request): email = data.get("email", None) if email == None: - return Response( { "error": "Something went wrong. Please try again later or contact the support team." @@ -153,7 +160,6 @@ def post(self, request): mobile_number = uuid.uuid4().hex email_verified = True else: - return Response( { "error": "Something went wrong. Please try again later or contact the support team." diff --git a/apps/app/components/account/github-login-button.tsx b/apps/app/components/account/github-login-button.tsx index e93abde88dc..80faecec5e3 100644 --- a/apps/app/components/account/github-login-button.tsx +++ b/apps/app/components/account/github-login-button.tsx @@ -34,7 +34,7 @@ export const GithubLoginButton: FC = (props) => { return (