Skip to content
Permalink
Browse files

Merge pyextra subtree

  • Loading branch information...
Vehicle Researcher
Vehicle Researcher committed Jun 6, 2019
2 parents f91df07 + 7ccae06 commit 59bd6b88373806baff545a003c1f42b9e41d0ff9
@@ -0,0 +1,70 @@
Metadata-Version: 1.1
Name: PyJWT
Version: 1.4.1
Summary: JSON Web Token implementation in Python
Home-page: http://github.com/jpadilla/pyjwt
Author: José Padilla
Author-email: hello@jpadilla.com
License: MIT
Description: # PyJWT

[![travis-status-image]][travis]
[![appveyor-status-image]][appveyor]
[![pypi-version-image]][pypi]
[![coveralls-status-image]][coveralls]
[![docs-status-image]][docs]

A Python implementation of [RFC 7519][jwt-spec].
Original implementation was written by [@progrium][progrium].

## Installing

```
$ pip install PyJWT
```

## Usage

```python
>>> import jwt
>>> encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'

>>> jwt.decode(encoded, 'secret', algorithms=['HS256'])
{'some': 'payload'}
```

## Tests

You can run tests from the project root after cloning with:

```
$ python setup.py test
```

[travis-status-image]: https://secure.travis-ci.org/jpadilla/pyjwt.svg?branch=master
[travis]: http://travis-ci.org/jpadilla/pyjwt?branch=master
[appveyor-status-image]: https://ci.appveyor.com/api/projects/status/h8nt70aqtwhht39t?svg=true
[appveyor]: https://ci.appveyor.com/project/jpadilla/pyjwt
[pypi-version-image]: https://img.shields.io/pypi/v/pyjwt.svg
[pypi]: https://pypi.python.org/pypi/pyjwt
[coveralls-status-image]: https://coveralls.io/repos/jpadilla/pyjwt/badge.svg?branch=master
[coveralls]: https://coveralls.io/r/jpadilla/pyjwt?branch=master
[docs-status-image]: https://readthedocs.org/projects/pyjwt/badge/?version=latest
[docs]: http://pyjwt.readthedocs.org
[jwt-spec]: https://tools.ietf.org/html/rfc7519
[progrium]: https://github.com/progrium

Keywords: jwt json web token security signing
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Topic :: Utilities
@@ -0,0 +1,49 @@
AUTHORS
CHANGELOG.md
LICENSE
MANIFEST.in
README.md
setup.cfg
setup.py
tox.ini
PyJWT.egg-info/PKG-INFO
PyJWT.egg-info/SOURCES.txt
PyJWT.egg-info/dependency_links.txt
PyJWT.egg-info/entry_points.txt
PyJWT.egg-info/requires.txt
PyJWT.egg-info/top_level.txt
jwt/__init__.py
jwt/__main__.py
jwt/algorithms.py
jwt/api_jws.py
jwt/api_jwt.py
jwt/compat.py
jwt/exceptions.py
jwt/utils.py
jwt/contrib/__init__.py
jwt/contrib/algorithms/__init__.py
jwt/contrib/algorithms/py_ecdsa.py
jwt/contrib/algorithms/pycrypto.py
tests/__init__.py
tests/compat.py
tests/test_algorithms.py
tests/test_api_jws.py
tests/test_api_jwt.py
tests/test_compat.py
tests/test_exceptions.py
tests/test_jwt.py
tests/utils.py
tests/contrib/__init__.py
tests/contrib/test_algorithms.py
tests/keys/__init__.py
tests/keys/jwk_ec_key.json
tests/keys/jwk_ec_pub.json
tests/keys/jwk_hmac.json
tests/keys/jwk_rsa_key.json
tests/keys/jwk_rsa_pub.json
tests/keys/testkey2_rsa.pub.pem
tests/keys/testkey_ec
tests/keys/testkey_ec.pub
tests/keys/testkey_rsa
tests/keys/testkey_rsa.cer
tests/keys/testkey_rsa.pub
@@ -0,0 +1 @@

@@ -0,0 +1,3 @@
[console_scripts]
jwt = jwt.__main__:main

@@ -0,0 +1,31 @@
../../../../bin/jwt
../jwt/__init__.py
../jwt/__init__.pyc
../jwt/__main__.py
../jwt/__main__.pyc
../jwt/algorithms.py
../jwt/algorithms.pyc
../jwt/api_jws.py
../jwt/api_jws.pyc
../jwt/api_jwt.py
../jwt/api_jwt.pyc
../jwt/compat.py
../jwt/compat.pyc
../jwt/contrib/__init__.py
../jwt/contrib/__init__.pyc
../jwt/contrib/algorithms/__init__.py
../jwt/contrib/algorithms/__init__.pyc
../jwt/contrib/algorithms/py_ecdsa.py
../jwt/contrib/algorithms/py_ecdsa.pyc
../jwt/contrib/algorithms/pycrypto.py
../jwt/contrib/algorithms/pycrypto.pyc
../jwt/exceptions.py
../jwt/exceptions.pyc
../jwt/utils.py
../jwt/utils.pyc
PKG-INFO
SOURCES.txt
dependency_links.txt
entry_points.txt
requires.txt
top_level.txt
@@ -0,0 +1,13 @@

[crypto]
cryptography

[flake8]
flake8
flake8-import-order
pep8-naming

[test]
pytest==2.7.3
pytest-cov
pytest-runner
@@ -0,0 +1 @@
jwt
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# flake8: noqa

"""
JSON Web Token implementation
Minimum implementation based on this spec:
http://self-issued.info/docs/draft-jones-json-web-token-01.html
"""


__title__ = 'pyjwt'
__version__ = '1.4.1'
__author__ = 'José Padilla'
__license__ = 'MIT'
__copyright__ = 'Copyright 2015 José Padilla'


from .api_jwt import (
encode, decode, register_algorithm, unregister_algorithm,
get_unverified_header, PyJWT
)
from .api_jws import PyJWS
from .exceptions import (
InvalidTokenError, DecodeError, InvalidAudienceError,
ExpiredSignatureError, ImmatureSignatureError, InvalidIssuedAtError,
InvalidIssuerError, ExpiredSignature, InvalidAudience, InvalidIssuer,
MissingRequiredClaimError
)
@@ -0,0 +1,135 @@
#!/usr/bin/env python

from __future__ import absolute_import, print_function

import json
import optparse
import sys
import time

from . import DecodeError, __package__, __version__, decode, encode


def main():

usage = '''Encodes or decodes JSON Web Tokens based on input.
%prog [options] input
Decoding examples:
%prog --key=secret json.web.token
%prog --no-verify json.web.token
Encoding requires the key option and takes space separated key/value pairs
separated by equals (=) as input. Examples:
%prog --key=secret iss=me exp=1302049071
%prog --key=secret foo=bar exp=+10
The exp key is special and can take an offset to current Unix time.\
'''
p = optparse.OptionParser(
usage=usage,
prog=__package__,
version='%s %s' % (__package__, __version__),
)

p.add_option(
'-n', '--no-verify',
action='store_false',
dest='verify',
default=True,
help='ignore signature and claims verification on decode'
)

p.add_option(
'--key',
dest='key',
metavar='KEY',
default=None,
help='set the secret key to sign with'
)

p.add_option(
'--alg',
dest='algorithm',
metavar='ALG',
default='HS256',
help='set crypto algorithm to sign with. default=HS256'
)

options, arguments = p.parse_args()

if len(arguments) > 0 or not sys.stdin.isatty():
if len(arguments) == 1 and (not options.verify or options.key):
# Try to decode
try:
if not sys.stdin.isatty():
token = sys.stdin.read()
else:
token = arguments[0]

token = token.encode('utf-8')
data = decode(token, key=options.key, verify=options.verify)

print(json.dumps(data))
sys.exit(0)
except DecodeError as e:
print(e)
sys.exit(1)

# Try to encode
if options.key is None:
print('Key is required when encoding. See --help for usage.')
sys.exit(1)

# Build payload object to encode
payload = {}

for arg in arguments:
try:
k, v = arg.split('=', 1)

# exp +offset special case?
if k == 'exp' and v[0] == '+' and len(v) > 1:
v = str(int(time.time()+int(v[1:])))

# Cast to integer?
if v.isdigit():
v = int(v)
else:
# Cast to float?
try:
v = float(v)
except ValueError:
pass

# Cast to true, false, or null?
constants = {'true': True, 'false': False, 'null': None}

if v in constants:
v = constants[v]

payload[k] = v
except ValueError:
print('Invalid encoding input at {}'.format(arg))
sys.exit(1)

try:
token = encode(
payload,
key=options.key,
algorithm=options.algorithm
)

print(token)
sys.exit(0)
except Exception as e:
print(e)
sys.exit(1)
else:
p.print_help()

if __name__ == '__main__':
main()

0 comments on commit 59bd6b8

Please sign in to comment.
You can’t perform that action at this time.