Skip to content

Commit

Permalink
fix: github auth login (#250)
Browse files Browse the repository at this point in the history
* fix: added PROJECT_ISSUES_LIST on the imports (#221)

* fix: github signin by parsing email

* refactor: changed variable names

---------

Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
Co-authored-by: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com>
Co-authored-by: Vamsi Kurama <vamsi.kurama@gmail.com>
  • Loading branch information
4 people committed Feb 8, 2023
1 parent 4ffa31f commit 56030b1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
18 changes: 12 additions & 6 deletions apiserver/plane/api/views/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -106,17 +105,26 @@ 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):
permission_classes = [AllowAny]

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)
Expand All @@ -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."
Expand All @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion apps/app/components/account/github-login-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const GithubLoginButton: FC<GithubLoginButtonProps> = (props) => {

return (
<Link
href={`https://github.com/login/oauth/authorize?client_id=${NEXT_PUBLIC_GITHUB_ID}&redirect_uri=${loginCallBackURL}`}
href={`https://github.com/login/oauth/authorize?client_id=${NEXT_PUBLIC_GITHUB_ID}&redirect_uri=${loginCallBackURL}&scope=read:user,user:email`}
>
<button className="flex w-full items-center rounded bg-black px-3 py-2 text-sm text-white opacity-90 duration-300 hover:opacity-100">
<Image
Expand Down
43 changes: 23 additions & 20 deletions apps/app/pages/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,30 @@ const SignInPage: NextPage = () => {
}
};

const handleGithubSignIn = (githubToken: string) => {
setLoading(true);
authenticationService
.socialAuth({
medium: "github",
credential: githubToken,
clientId: NEXT_PUBLIC_GITHUB_ID,
})
.then(async () => {
await onSignInSuccess();
})
.catch((err) => {
console.log(err);
setToastAlert({
title: "Error signing in!",
type: "error",
message: "Something went wrong. Please try again later or contact the support team.",
const handleGithubSignIn = useCallback(
(credential: string) => {
setLoading(true);
authenticationService
.socialAuth({
medium: "github",
credential,
clientId: NEXT_PUBLIC_GITHUB_ID,
})
.then(async () => {
await onSignInSuccess();
})
.catch((err) => {
console.log(err);
setToastAlert({
title: "Error signing in!",
type: "error",
message: "Something went wrong. Please try again later or contact the support team.",
});
setLoading(false);
});
setLoading(false);
});
};
},
[onSignInSuccess, setToastAlert]
);

return (
<DefaultLayout
Expand Down

1 comment on commit 56030b1

@vercel
Copy link

@vercel vercel bot commented on 56030b1 Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

plane-dev – ./apps/app

plane-dev-caravel.vercel.app
plane-dev-git-develop-caravel.vercel.app
plane-dev.vercel.app

Please sign in to comment.