Skip to content

Error when authenticated through OAuth without the user scope #797

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

Closed
baldychristophe opened this issue Mar 19, 2018 · 2 comments · Fixed by #992
Closed

Error when authenticated through OAuth without the user scope #797

baldychristophe opened this issue Mar 19, 2018 · 2 comments · Fixed by #992

Comments

@baldychristophe
Copy link

baldychristophe commented Mar 19, 2018

Hi,

According to the github documentation, the API return on /user is different when the user is authenticated through OAuth without the user scope from when it is authenticated with the user scope.
https://developer.github.com/v3/users/#get-the-authenticated-user

But the library seems to handle only users with the user scope.

When the user scope is not used, the api returns fewer fields: for instance, the disk_usage field is not returned, and when trying to load the return into an AuthenticatedUser here:

github3.py/github3/github.py

Lines 1004 to 1019 in bf44c16

@requires_auth
def me(self):
"""Retrieve the info for the authenticated user.
.. versionadded:: 1.0
This was separated from the ``user`` method.
:returns:
the representation of the authenticated user.
:rtype:
:class:`~github3.users.AuthenticatedUser`
"""
url = self._build_url('user')
json = self._json(self._get(url), 200)
return self._instance_or_null(users.AuthenticatedUser, json)

I get the following error:

IncompleteResponse: None The library was expecting more data in the response (KeyError('disk_usage',)). Either GitHub modified it's response body, or your token is not properly scoped to retrieve this information.

I think this function should not always try to load the result into an AuthenticatedUser, but first check the fields of the API's response and try to load a User if some fields are missing.

Because of this behavior, we have to keep using the version 1.0.0a4 and cannot upgrade to version 1.0.1

If you think this is a valid issue, I can work on a pull request to fix it.

Thanks

@omgjlk
Copy link
Collaborator

omgjlk commented Mar 20, 2018

This does indeed look like a real bug. Feels like we should be returning something like a AuthenticatedShortUser, or something like that. Whether or not we have a path to "upgrade" a ShortUser up to a full User is an interesting thought. I don't know if that really makes sense. Really ugly though that this method would return two different things, that's a pattern we don't actually like.

@omgjlk omgjlk added the Bug label Mar 20, 2018
mtb-beta added a commit to mtb-beta/github3.py that referenced this issue Nov 30, 2018
mtb-beta added a commit to mtb-beta/github3.py that referenced this issue Nov 30, 2018
@mtb-beta
Copy link

mtb-beta commented Dec 3, 2018

I think that It is difficult to return something like a AuthenticatedShortUser because github's authenticated user information API returns two kinds of information.

I hope this issue fix. So I created the pull requests #911.
Please review. Best regards.

@omgjlk omgjlk linked a pull request Aug 12, 2020 that will close this issue
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.

3 participants