Contents¶
Overview¶
docs | |
---|---|
tests | |
package |
JWT implementation for ZSL framework. This modules adds security possibilities to ZSL.
- Free software: BSD license
Usage¶
Add zsl_jwt.module.JWTModule to the modules in your IoCContainer and provide a zsl_jwt.configuration.JWTConfiguration in your configuration under JWT variable.
Documentation¶
See more in https://zsl_jwt.readthedocs.io/
Development¶
To run the all tests run:
tox
Note, to combine the coverage data from all the tox environments run:
Windows | set PYTEST_ADDOPTS=--cov-append
tox
|
---|---|
Other | PYTEST_ADDOPTS=--cov-append tox
|
Reference¶
API reference of zsl_jwt
¶
zsl_jwt.codec
¶
The module provides the two main functions encode()
and decode()
which encode and decode the given payload.
-
zsl_jwt.codec.
CLAIMS
= (u'exp', u'nbf', u'iss', u'aud', u'iat')¶ The list of JWT claim names.
-
exception
zsl_jwt.codec.
ZslJwtInvalidAudienceError
[source]¶ When the audience of the token does not match the audience of the profile used to decode the token.
-
zsl_jwt.codec.
decode
(*args, **kwargs)[source]¶ Decodes the encoded token.
Parameters: - token – The encoded token.
- jwt_configuration – The configuration, injected.
- profile – The profile name used for encoding.
Returns: The decoded payload.
-
zsl_jwt.codec.
encode
(*args, **kwargs)[source]¶ Encodes the payload. :param payload: The payload to be encoded. :param jwt_configuration: The JWT configuration, it is injected. :param algorithm: Algorithm name. A reasonable default is provided. :param profile: The JWT profile to be used. See
Returns: The JWT token.
zsl_jwt.configuration
¶
-
class
zsl_jwt.configuration.
JWTConfiguration
(default_secret=None, default_profile=None, profiles=None)[source]¶ The main JWT configuration object. Consists of several token profiles used for encoding/decoding. See
zsl_jwt.configuration.JWTProfile
.
-
class
zsl_jwt.configuration.
JWTProfile
(secret, expiration=None, not_before=None, issuer=u'zsl_jwt', audience=u'zsl_jwt', algorithm=u'HS256')[source]¶ - Each profile consits of its own
- secret and all the JWT claims definitions:
- audience: str - must match the audience in the decoding,
- issuer name: str - just an information about the token issuer,
- expiration: datetime.timedelta specifying when token becomes invalid,
- not_before: datetime.timedelta specifying when token becomes valid,
- algorithm: encryption algorithm used to create the token.
-
algorithm
¶
-
audience
¶ The audience of the token for which the token is intended. This must match the audience used for decoding. This is a standard JWT claim.
-
expiration
¶ The time interval specifying when the token becomes invalid. The token is valid until time now + expiration. This is a standard JWT claim.
-
issuer
¶ The issuer name. This is a standard JWT claim.
-
not_before
¶ The time interval specifying when the token becomes valid. The token is valid from time now + not_before. This is a standard JWT claim.
-
secret
¶ Key/secret used for encryption.
zsl_jwt.module
¶
-
class
zsl_jwt.module.
JWTModule
[source]¶ JWT module activation. Add to your IoCContainer to enable JWT support.
It just provides the
zsl_jwt.configuration.JWTConfiguration
so that the users may read the JWT configuration.-
JWT_CONFIG_NAME
= u'JWT'¶ Variable name in config used for JWT configuration
-
zsl_jwt.configuration
¶
The configuration of the authentication.
-
class
zsl_jwt.auth.configuration.
AuthConfiguration
(authentication_service_class)[source]¶ Auth module configuration. It holds the string identifying the authentication service.
-
authentication_service_class
¶ The string identifying the class implementing the
zsl_jwt.auth.service.AuthenticationService
which is used for login controller.
-
zsl_jwt.auth.module
¶
This ZSL module reads the auth configuration and provides
zsl_jwt.auth.configuration.AuthConfiguration
and an instance of
zsl_jwt.auth.service.AuthenticationService
.
zsl_jwt.auth.service
¶
The abstraction of authentication service and user information.
-
class
zsl_jwt.auth.service.
AuthenticationService
[source]¶ The service used for verifying username and password and querying the user information.
-
class
zsl_jwt.auth.service.
StandardUserInformation
(username, roles, user_object)[source]¶ Standard user information - contains username, roles (list of strings) and a user object, if wanted (may be
None
)-
roles
¶
-
user_object
¶
-
username
¶
-
zsl_jwt.controller
¶
Contains the login function.
-
zsl_jwt.auth.controller.
authenticate
(*args, **kwargs)[source]¶ The “login” function, from the given username/password returns the JWT. Use only as a delegate function in handling of tasks.
Parameters: - username –
- password –
- authentication_service – Injected. Uses
zsl_jwt.auth.service.AuthenticationService
to query the database.
Returns: error response if the credentials are invalid or jwt.
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
Bug reports¶
When reporting a bug please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Documentation improvements¶
zsl_jwt could always use more documentation, whether as part of the official zsl_jwt docs, in docstrings, or even on the web in blog posts, articles, and such.
Feature requests and feedback¶
The best way to send feedback is to file an issue at https://github.com/AtteqCom/zsl_jwt/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that code contributions are welcome :)
Development¶
To set up zsl_jwt for local development:
Fork zsl_jwt (look for the “Fork” button).
Clone your fork locally:
git clone git@github.com:your_name_here/zsl_jwt.git
Create a branch for local development:
git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, run all the checks, doc builder and spell checker with tox one command:
tox
Commit your changes and push your branch to GitHub:
git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
If you need some code review or feedback while you’re developing the code just make the pull request.
For merging, you should:
- Include passing tests (run
tox
) [1]. - Update documentation when there’s new API, functionality etc.
- Add a note to
CHANGELOG.rst
about the changes. - Add yourself to
AUTHORS.rst
.
[1] | If you don’t have all the necessary python versions available locally you can rely on Travis - it will run the tests for each change you add in the pull request. It will be slower though ... |
Tips¶
To run a subset of tests:
tox -e envname -- py.test -k test_myfeature
To run all the test environments in parallel (you need to pip install detox
):
detox
Authors¶
- Martin Babka - babka@atteq.com, www.atteq.com