├── .gitignore ├── LICENSE ├── MAINTAINERS ├── README.rst ├── httpie_zign.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | build 3 | *.egg* 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 Zalando SE 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /MAINTAINERS: -------------------------------------------------------------------------------- 1 | Henning Jacobs 2 | Matthias Kerk 3 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | =========== 2 | httpie-zign 3 | =========== 4 | 5 | STUPS Zign OAuth 2 plugin for the `HTTPie `_ command line HTTP client. 6 | 7 | `Zign `_ is STUPS' command line client to generate OAuth2 access tokens. 8 | 9 | 10 | Installation 11 | ------------ 12 | 13 | .. code-block:: bash 14 | 15 | $ pip install httpie-zign 16 | 17 | 18 | You should now see ``zign`` under ``--auth-type`` in ``$ http --help`` output. 19 | 20 | 21 | Usage 22 | ----- 23 | 24 | This plugin takes the Zign token name as the ``--auth`` username. 25 | The ``--auth`` password is used to specify to OAuth scopes. 26 | A named Zign OAuth 2 token is created and used with the specified scopes: 27 | 28 | .. code-block:: bash 29 | 30 | $ http --auth-type=zign --auth=mytok:myscope https://example.org 31 | $ http --auth-type=zign -a mytok:myscope1,scope2 https://example.org 32 | $ http --auth-type=zign -a mytok: https://example.org # use default scopes 33 | 34 | You can list the created tokens using the Zign CLI: 35 | 36 | .. code-block:: bash 37 | 38 | $ zign li 39 | 40 | You can set the default ``--auth-type=zign`` option in the ``~/.httpie/config.json`` file for convenience: 41 | 42 | .. code-block:: bash 43 | 44 | $ echo '{"default_options": ["--auth-type=zign"]}' > ~/.httpie/config.json 45 | $ http -a mytok: https://example.org # that's much shorter now :-) 46 | 47 | -------------------------------------------------------------------------------- /httpie_zign.py: -------------------------------------------------------------------------------- 1 | """ 2 | STUPS Zign OAuth plugin for HTTPie. 3 | 4 | """ 5 | from httpie.plugins import AuthPlugin 6 | import zign.api 7 | 8 | 9 | __version__ = '0.2' 10 | __author__ = 'Henning Jacobs' 11 | __licence__ = 'Apache 2.0' 12 | 13 | 14 | class InvalidZignToken(Exception): 15 | def __init__(self, token_name): 16 | self.token_name = token_name 17 | 18 | def __str__(self): 19 | return 'invalid or expired Zign OAuth token: "{}"'.format(self.token_name) 20 | 21 | 22 | class ZignAuth: 23 | def __init__(self, token_name, scopes): 24 | self.token_name = token_name 25 | self.scopes = scopes 26 | 27 | def __call__(self, r): 28 | access_token = zign.api.get_token(self.token_name, self.scopes) 29 | if not access_token: 30 | raise InvalidZignToken(self.token_name) 31 | r.headers['Authorization'] = 'Bearer {}'.format(access_token) 32 | return r 33 | 34 | 35 | class ZignPlugin(AuthPlugin): 36 | 37 | name = 'Zign OAuth 2.0' 38 | auth_type = 'zign' 39 | description = '' 40 | 41 | def get_auth(self, username, password): 42 | scopes_str = password or '' 43 | scopes = list(filter(None, scopes_str.split(','))) 44 | return ZignAuth(username, scopes) 45 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | 4 | setup( 5 | name='httpie-zign', 6 | description='Zign OAuth 2 plugin for HTTPie.', 7 | long_description=open('README.rst').read().strip(), 8 | version='0.2', 9 | author='Henning Jacobs', 10 | author_email='henning.jacobs@zalando.de', 11 | license='Apache License 2.0', 12 | url='https://github.com/zalando-stups/httpie-zign', 13 | py_modules=['httpie_zign'], 14 | zip_safe=False, 15 | entry_points={ 16 | 'httpie.plugins.auth.v1': [ 17 | 'httpie_zign = httpie_zign:ZignPlugin' 18 | ] 19 | }, 20 | install_requires=[ 21 | 'httpie>=0.7.0', 22 | 'stups-zign>=1.0.17' 23 | ], 24 | classifiers=[ 25 | 'Development Status :: 5 - Production/Stable', 26 | 'Programming Language :: Python', 27 | 'Environment :: Plugins', 28 | 'License :: OSI Approved :: Apache Software License', 29 | 'Topic :: Internet :: WWW/HTTP', 30 | 'Topic :: Utilities' 31 | ], 32 | keywords='httpie oauth oauth2 stups zign access token', 33 | ) 34 | --------------------------------------------------------------------------------