Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ob-stripe
Copy link
Contributor

r? @brandur-stripe
cc @stripe/api-libraries

This PR updates the OAuth implementation to be much closer to the stripe-ruby implementation:

  • no more dedicated OAuthRequestor class. The APIRequestor class can now interpret both API and OAuth errors

  • dedicated exception classes for each OAuth error type

This is technically a breaking change, but we never documented this feature (and won't until ~all libraries support it) so I don't think this necessarily warrants a major version bump.

The one thing I'm not happy about is the OAuthInvalidRequestError class name, to differentiate it from the existing InvalidRequestError class. I think it might be worth it moving all the OAuth errors in a different module, e.g. oauth_error, so they have their own namespace and we can reuse the InvalidRequestError class name.

wdyt?

@ob-stripe ob-stripe force-pushed the ob-update-oauth branch 2 times, most recently from c1cb321 to a0de4e9 Compare June 2, 2017 18:33
except (KeyError, TypeError):
raise error.APIError(
"Invalid response object from API: %r (HTTP response code "
"was %d)" % (rbody, rcode),
rbody, rcode, resp)

err = None
if isinstance(error_data, basestring):
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just add a comment here on why we're doing this. I think that the minor structural difference between an OAuth and API error is pretty subtle unless you already know about it.

@brandur-stripe
Copy link
Contributor

@ob-stripe Looks good to me! This feels like it strips some complexity out and standardizes on some standard paths, so big +1.

The one thing I'm not happy about is the OAuthInvalidRequestError class name, to differentiate it from the existing InvalidRequestError class. I think it might be worth it moving all the OAuth errors in a different module, e.g. oauth_error, so they have their own namespace and we can reuse the InvalidRequestError class name.

Yeah, in my opinion adding a new module here would be fine.

This is technically a breaking change, but we never documented this feature (and won't until ~all libraries support it) so I don't think this necessarily warrants a major version bump.

Good point. I just ran a Splunk query and it doesn't look there's any activity on /oauth/token coming from stripe-python right now (checked the last 24 hours and re-running for the last week now), so yeah it might be fine to refactor this a bit.

@brandur-stripe
Copy link
Contributor

Quick follow up: no requests from stripe-python to /oauth/token over the last week, so I think we're okay.

@ob-stripe ob-stripe force-pushed the ob-update-oauth branch 3 times, most recently from 466a9ee to d365b5b Compare June 4, 2017 22:36
@ob-stripe
Copy link
Contributor Author

Alright, I moved the OAuth error classes into their own oauth_error module.

ptal @brandur-stripe

@ob-stripe ob-stripe changed the title [WIP] Update OAuth implementation Update OAuth implementation Jun 4, 2017
@brandur-stripe
Copy link
Contributor

Nice!

Just out of curiosity, any thoughts on oauth_error versus error.oauth or error.oauth_error? I don't mind that much either way, but I just wanted to make sure we thought about it.

@ob-stripe ob-stripe force-pushed the ob-update-oauth branch 2 times, most recently from 9ee9a83 to 4ad315a Compare June 6, 2017 21:35
@ob-stripe
Copy link
Contributor Author

@brandur-stripe Great point, I hadn't thought of this. I agree that error.oauth would be a bit better so I gave it a try, but I ran into some issues. Doing this requires turning error from a module (error.py) into a package (error/__init__.py) so we can create the oauth.py submodule inside the error namespace.

This works on Python 2, but apparently causes circular import errors on Python 3 for some reason. This is probably fixable but I'm wary that changing how the imports are done could cause some unforeseen side-effects, so I'd rather play it safe and reverted to using the oauth_error module.

@brandur-stripe
Copy link
Contributor

This works on Python 2, but apparently causes circular import errors on Python 3 for some reason. This is probably fixable but I'm wary that changing how the imports are done could cause some unforeseen side-effects, so I'd rather play it safe and reverted to using the oauth_error module.

Thanks for looking into it; that sounds good to me. I don't think there's a huge ergonomic different either way, so it seems fine to leave as oauth_error.

@brandur-stripe brandur-stripe merged commit 6615576 into master Jun 7, 2017
@brandur-stripe brandur-stripe deleted the ob-update-oauth branch June 7, 2017 18:30
@brandur-stripe
Copy link
Contributor

As discussed, released as 1.59.0.

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 this pull request may close these issues.

2 participants