-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add and expose auth types: MultiAuth ApiToken* #137
Conversation
@cognifloyd - Looks like one unit test is failing the CI build:
Thanks for contributing, by the way! |
@prkumar Yeah. I haven't looked at the tests yet. I will do that hopefully this week. Conceptually, are you okay with the direction of this PR? eg I'm exporting the auth classes in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks good. I think ApiTokenParam
and ApiTokenHeader
are great additions to the library, and we exposing the auth classes is a good move too. I just have a few suggestions, which I've added below.
I haven't had experience with APIs that use a multi-auth strategy, so I'm interested to see an example: do you know of any public APIs that support this sort of authentication? |
I don't think very many (if any) APIs require multiple forms of auth on the server side. I'm designing an API that might require multiple tokens on the server side, not just for intermediary auth, but it's a very specific use-case peculiar to our internal infrastructure. I don't know of any generally available APIs that require multiple forms of auth on the server side. However, many clients require multiple forms of auth to, for example, authenticate to an HTTP proxy and to the API server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of subclassing, we could create some kind of auth meta class, or add a decorator that turns a class into an auth class?
Or should API libraries have some kind of factory function that their consumers would use to pass in the token?
Codecov Report
@@ Coverage Diff @@
## master #137 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 41 41
Lines 2052 2083 +31
Branches 163 167 +4
=====================================
+ Hits 2052 2083 +31
Continue to review full report at Codecov.
|
80894f7
to
b43fdcb
Compare
@prkumar done including tests (codecov @ 100%).
What do you think? I can revert the changes to BasicAuth and ProxyAuth if you'd like (changing that made it more consistent in internal implementation details, but is otherwise unnecessary). I can also squash my commits if you'd like. |
@cognifloyd - This looks great! Thanks so much for adding coverage and for extending the After merging, I'll also make a separate commit to add you to the
Alternatively, you could make a separate commit to this PR with that change. Whatever works best for you! Thanks for contributing! |
I added myself to AUTHORS.rst |
244acd3
to
d4299a1
Compare
This exposes all auth methods and adds these additional auth classes: - MultiAuth - ApiTokenParam - ApiTokenHeader The purpose of MultiAuth is to allow for multiple auth methods. This may be required when an API user needs to supply intermediate credentials-- as when using ProxyAuth to authenticate with an intermediate proxy-- or when an API requires multiple auth tokens. MultiAuth acts like a list so that users can append, extend or iterate over the contained auth methods. The purpose of the the ApiToken* auth methods is to allow both direct API users and API library authors to easily provide auth tokens in a standardized manner. When directly supplying the auth token, some users may prefer to supply both the parameter/header name and the token at the same time. Thus, we allow such users to directly use the generic ApiToken* auth methods. For API library authors that want to supply the parameter/header name in a reusable way (so users only have to supply the token), they can use properties on an ApiToken* subclass to define the relvant query parameter or header. This also refactors BasicAuth and ProxyAuth as subclasses of ApiTokenHeader to harmonize the implementation details of all the auth methods. Any uplink users that directly accessed the private _auth_str attribute will need to replace that with _header_value.
d4299a1
to
27803a2
Compare
Squashed and rebased on master. |
Document Auth methods from #137
This adds more auth classes designed to be used when initializing a
Consumer subclass. There are two generic AuthToken types that may
be used directly or may be subclassed by API library authors to define
the relevant query parameter or header.
There is also a MultiAuth type which allows for passing in a list of auth
methods, so that they all take effect.
The purpose of the generic AuthToken types is to make it simple for
uplink-based libraries to provide a standardized way to authenticate
with their api.
The purpose of MultiAuth is to allow for multiple auth methods. This may
be required when ProxyAuth needs to be combined with another auth
method, or when an API requires multiple auth tokens.