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

Update github.py for fastapi client #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions loginpass/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class GitHub(object):
'userinfo_endpoint': 'https://api.github.com/user',
}

def userinfo(self, **kwargs):
resp = self.get(self.OAUTH_CONFIG['userinfo_endpoint'], **kwargs)
async def userinfo(self, **kwargs):
resp = await self.get(self.OAUTH_CONFIG['userinfo_endpoint'], **kwargs)
data = resp.json()

params = {
Expand All @@ -45,9 +45,11 @@ def userinfo(self, **kwargs):
# If that is the case we get all the users emails regardless if private or note
# and use the one he/she has marked as `primary`
if params.get('email') is None:
resp = self.get('user/emails', **kwargs)
resp = await self.get('user/emails', **kwargs)
resp.raise_for_status()
data = resp.json()
params["email"] = next(email['email'] for email in data if email['primary'])
params["email"], params["email_verified"] = next(
(email["email"], email["verified"]) for email in data if email["primary"]
)

return UserInfo(params)