Skip to content

Check for errors in authorization code response #680

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

Merged
merged 2 commits into from
Jun 12, 2019

Conversation

MrkGrgsn
Copy link
Contributor

@MrkGrgsn MrkGrgsn commented Jun 6, 2019

Fixes #290 by adding error checking to parse_authorization_code_response() before any validation of the code param is done.

Note that I also shifted the state check before both the error and code checks - state is required in the response and if it isn't correct, why would we trust any of the other params? This is a little out-of-scope so let me know if you'd prefer I revert that bit.

Also note that this is a breaking change as I mentioned in #290 (comment) because client error handling behaviour will need to change.

@JonathanHuot
Copy link
Member

Hi @MrkGrgsn !

This looks a good change to me.

However, before approving it, and in order to add a little bit of context, could you tell which library are you using and/or how do you use this library ? (sample of code)

Thanks !

@JonathanHuot JonathanHuot self-assigned this Jun 7, 2019
@MrkGrgsn
Copy link
Contributor Author

Hi @JonathanHuot

I'm working on an ORCID integration with a Django app using requests_oauthlib. The goal is to link the local user account with their ORCID record and later query and retrieve some resources. I'm using the 'Web Application Flow' aka Authorisation Code Grant Type.

I can't link to the source code but the code pre-PR is similar to this simplified example showing the view that handles the redirect from the authorisation server:

class FetchAccessTokenView():
    def get():
        try:
            token = session.fetch_token()
        except MissingCodeError:
            error = request.GET.get('error', None)
            if error:
                if error == 'access_denied':
                    # ask user to reconsider
                elif error == 'temporarily_unavailable':
                    # ask user to try again later
            else:
                #  unexpected, log and provide feedback

Which will break post-PR. On the other hand, you could check the error param prior to calling fetch_token and this would not break post-PR but we're still doing work that oauthlib can do.

With the attached PR, I can simply use the try/except without any extra handling of the error param:

class FetchAccessTokenView():
    def get():
        try:
            token = session.fetch_token()
        except AccessDeniedError:
            # ask user to reconsider
        except TemporarilyUnavailableError
            # ask user to try again later
        except MissingCodeError:
            # unexpected, log and provide feedback

@JonathanHuot JonathanHuot added Bug OAuth2-Client This impact the client part of OAuth2. labels Jun 12, 2019
Copy link
Member

@JonathanHuot JonathanHuot left a comment

Choose a reason for hiding this comment

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

LGTM ! I don't know why this issue last for so long ! Many thanks for this huge improvement (tiny change but big impact!).

@JonathanHuot JonathanHuot added this to the 3.1.0 milestone Jun 12, 2019
@JonathanHuot JonathanHuot merged commit 76d8d34 into oauthlib:master Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug OAuth2-Client This impact the client part of OAuth2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

parse_authorization_code_response has no error checking
2 participants