Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 13, 2023. It is now read-only.
/python-jwtPublic archive

Python module for generating and verifying JSON Web Tokens

License

NotificationsYou must be signed in to change notification settings

davedoesdev/python-jwt

Repository files navigation

Module for generating and verifyingJSON Web Tokens.

All versions of python-jwt are now DEPRECATED. I don't have the time to maintain this module.

  • Note: Versions 3.3.4 and later fix avulnerability (CVE-2022-39227) in JSON Web Token verification which lets an attacker with a valid token re-use its signature with modified claims. CVE to follow. Please upgrade!
  • Note: From version 2.0.1 the namespace has changed fromjwt topython_jwt, in order to avoid conflict withPyJWT.
  • Note: Versions 1.0.0 and later fix avulnerability in JSON Web Token verification so please upgrade if you're using this functionality. The API has changed so you will need to update your application.verify_jwt now requires you to specify which signature algorithms are allowed.
  • Usesjwcrypto to do the heavy lifting.
  • SupportsRS256,RS384,RS512,PS256,PS384,PS512,HS256,HS384,HS512,ES256,ES384,ES512,ES256K,EdDSA andnone signature algorithms.
  • Unit tests, including tests for interoperability withjose.
  • Supports Python 3.6+.Note:generate_jwt returns the token as a Unicode string.

Example:

importpython_jwtasjwt,jwcrypto.jwkasjwk,datetimekey=jwk.JWK.generate(kty='RSA',size=2048)payload= {'foo':'bar','wup':90 };token=jwt.generate_jwt(payload,key,'PS256',datetime.timedelta(minutes=5))header,claims=jwt.verify_jwt(token,key, ['PS256'])forkinpayload:assertclaims[k]==payload[k]

The API is describedhere.

Installation

pip install python_jwt

Another Example

You can read and write keys from and toPEM-format strings:

importpython_jwtasjwt,jwcrypto.jwkasjwk,datetimekey=jwk.JWK.generate(kty='RSA',size=2048)priv_pem=key.export_to_pem(private_key=True,password=None)pub_pem=key.export_to_pem()payload= {'foo':'bar','wup':90 };priv_key=jwk.JWK.from_pem(priv_pem)pub_key=jwk.JWK.from_pem(pub_pem)token=jwt.generate_jwt(payload,priv_key,'RS256',datetime.timedelta(minutes=5))header,claims=jwt.verify_jwt(token,pub_key, ['RS256'])forkinpayload:assertclaims[k]==payload[k]

Licence

MIT

Tests

maketest

Lint

make lint

Code Coverage

make coverage

coverage.py results are availablehere.

Coveralls page ishere.

Benchmarks

make bench

Here are some results on a laptop with an Intel Core i5-4300M 2.6Ghz CPU and 8Gb RAM running Ubuntu 17.04.

Generate Keyuser (ns)sys (ns)real (ns)
RSA103,100,000200,000103,341,537
Generate Tokenuser (ns)sys (ns)real (ns)
HS256220,0000226,478
HS384220,0000218,233
HS512230,0000225,823
PS2561,530,00010,0001,536,235
PS3841,550,00001,549,844
PS5121,520,00010,0001,524,844
RS2561,520,00010,0001,524,565
RS3841,530,00001,528,074
RS5121,510,00001,526,089
Load Keyuser (ns)sys (ns)real (ns)
RSA210,0003,000210,791
Verify Tokenuser (ns)sys (ns)real (ns)
HS256100,0000101,478
HS384100,00010,000103,014
HS512110,0000104,323
PS256230,0000231,058
PS384240,0000237,551
PS512240,0000232,450
RS256230,0000227,737
RS384230,0000230,698
RS512230,0000228,624

About

Python module for generating and verifying JSON Web Tokens

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp