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

init for jwt identity #147

Merged
merged 3 commits into from
Apr 25, 2018
Merged

init for jwt identity #147

merged 3 commits into from
Apr 25, 2018

Conversation

alexpantyukhin
Copy link
Contributor

@alexpantyukhin alexpantyukhin commented Apr 9, 2018

Fix #1

@codecov
Copy link

codecov bot commented Apr 9, 2018

Codecov Report

Merging #147 into master will increase coverage by 0.13%.
The diff coverage is 96.36%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #147      +/-   ##
=========================================
+ Coverage   94.97%   95.1%   +0.13%     
=========================================
  Files          10      12       +2     
  Lines         517     572      +55     
  Branches       18      19       +1     
=========================================
+ Hits          491     544      +53     
- Misses         20      22       +2     
  Partials        6       6
Impacted Files Coverage Δ
aiohttp_security/jwt_identity.py 100% <100%> (ø)
tests/test_jwt_identity.py 95.12% <95.12%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29166f4...f72ae9d. Read the comment docs.

@alexpantyukhin
Copy link
Contributor Author

I would like that the consumer has the ability to not install PyJWT if JWTIdentityPolicy is not used. But I'm not sure that this is critical.

"""

from .abc import AbstractIdentityPolicy
import jwt
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice idea! thanks!

def __init__(self, secret, algorithm=None, param_name=None):
self.secret = secret
self.algorithm = 'HS256' if algorithm is None else algorithm
self.param_name = 'Authorization' if param_name is None else param_name
Copy link
Member

Choose a reason for hiding this comment

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

What is the use-case for custom header name?
Every extra argument has maintenance and mental burden. It forces users to learn and remember never used API names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.. param_name is overhead .

return identity['identity']

async def remember(self, request, response, identity, **kwargs):
encoded_identity = jwt.encode({'identity': identity},
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the purpose of the method.
remember()/forget() pair is used to save/clear HTTP cookies on session-based auth, here you do something very different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asvetlov Yes, you are right: remember is not totally appropriate name for this action. But if I correctly understand, jwt authentication approach doesn't imply for storing jwt token (excluding storing it on client side). For this action the most suitable name would be login which provides jwt token in the result or 403 otherwise. But for now we should to implement AbstractIdentityPolicy and use the same approach for eachone identity way.

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep remember()/forget() empty.
login is a client method, the client should acquire JWT by making a custom HTTP request to some resource. After that he is responsible for providing Authorization header properly.

@alexpantyukhin
Copy link
Contributor Author

@asvetlov review notes are fixed.

try:
import jwt
except ImportError:
jwt = None
Copy link
Member

@jettify jettify Apr 12, 2018

Choose a reason for hiding this comment

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

Please add # pragma: no cover here in order to shut up coverage check

return identity['identity']

async def remember(self, request, response, identity, **kwargs):
pass
Copy link
Member

Choose a reason for hiding this comment

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

should we add # pragma: no cover here also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jettify Yeah :) it's fun that if mark remember with # pragma: no cover then flake8 doesn't allow to pass tests :)

@jettify
Copy link
Member

jettify commented Apr 12, 2018

Branch is a bit out of date, PR should be rebased

@alexpantyukhin
Copy link
Contributor Author

@jettify thank you!

@alexpantyukhin
Copy link
Contributor Author

I have no idea how to win the codecov :)

@alexpantyukhin
Copy link
Contributor Author

@asvetlov thank you a lot!

@asvetlov asvetlov merged commit 27ffe6d into aio-libs:master Apr 25, 2018
@asvetlov asvetlov mentioned this pull request Apr 25, 2018
@alexpantyukhin alexpantyukhin deleted the wip_add_jwt branch April 26, 2018 11:21
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.

3 participants