Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github OAuth with non public email #32

Closed
kairichard opened this issue Jul 26, 2019 · 4 comments · Fixed by #36
Closed

Github OAuth with non public email #32

kairichard opened this issue Jul 26, 2019 · 4 comments · Fixed by #36

Comments

@kairichard
Copy link
Contributor

The UserInfo object does not contain the email when requesting a non-public email with {'scope': 'user:email'}. As a workaround, it is suggested to get the email with the token that was received see - https://stackoverflow.com/questions/35373995/github-user-email-is-null-despite-useremail-scope

A possible implementation would extend GitHub.profile with self.get("user/emails") and use whatever is returned there in case the initial email is None. Would you accept PR on this?

@lepture
Copy link
Member

lepture commented Jul 27, 2019

@kairichard Yes, please.

@kairichard
Copy link
Contributor Author

It would probably go in this direction - does that seem reasonable to you?

class GithubPrivateEmail(GitHub):

    def profile(self, **kwargs):
        profile = super().profile(**kwargs)
        if profile.get("email") is not None:
            return profile

        resp = self.get("user/emails")
        resp.raise_for_status()
        data = resp.json()
        # There should only be one `primary`
        profile["email"] = next(email["email"] for email in data if email["primary"])
        return profile

@lepture
Copy link
Member

lepture commented Jul 29, 2019

@kairichard how about just re-implement GitHub#profile method?

@kairichard
Copy link
Contributor Author

@lepture would also work yes, going to come back with a PR next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants