Coder Social home page Coder Social logo

teracyhq / httpie-jwt-auth Goto Github PK

View Code? Open in Web Editor NEW
169.0 169.0 12.0 71 KB

JWTAuth (JSON Web Tokens) auth plugin for HTTPie

License: BSD 3-Clause "New" or "Revised" License

Python 97.86% Makefile 1.28% Shell 0.86%
httpie jwt jwt-authentication jwt-token python

httpie-jwt-auth's People

Contributors

hieptranquoc avatar hoatle avatar jacquerie avatar phuonglm avatar quantifiedcode-bot avatar shtouff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

httpie-jwt-auth's Issues

Fetch token dynamically

It would be helpful if a URL can be specified (using an env var) which is used to obtain the token. Ideally then use the username and password provided via --auth=.

The token fetch and use sequence would then be triggered upon response header Www-Authenticate:, which also typically contains keyword JWT or Bearer to indicate which prefix was expected.

should check and release v1.0.0

it seems that we completed all the expected features and we reach good stability, we can release it as 1.0.0 to mark it as production-ready, backward compatibility is guaranteed for the next 1.x and 2.0.0 releases.

Usage example and quotations marks

System: Windows 10
Build: Latest Stable (0.2.1)

Hello.
In usage example:
http --auth-type=jwt --auth='<token>:' example.org

So if i type part after --auth in single quotation marks, i get an invalid token:
Bearer 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVC
(this quotation mark should not be after Bearer keyword)

But without quotation marks and with double quotation marks it works fine.

http --auth-type=jwt --auth=<token>: example.org
http --auth-type=jwt --auth="<token>:" example.org

HTTPie 2.0.0 ImportError: cannot import name 'ExitStatus'

Executing with HTTPie v2.0.0 with Python 3.6 e.g.:
http -v -b --output C:\Directory\JSON_Reply.json --auth-type=jwt --auth="adf21214fds254125" POST http://web_address.com.au/api @C:\Directory\JSON.json

Error:

File....\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
File....\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
File....\Python36\Scripts\http.exe\__main__.py", line 7, in <module>
File....\python36\lib\site-packages\httpie\__main__.py", line 11, in main
    exit_status = main()
File....\python36\lib\site-packages\httpie\core.py", line 36, in main
    plugin_manager.load_installed_plugins()
File....\python36\lib\site-packages\httpie\plugins\manager.py", line 34, in load_installed_plugins
    plugin = entry_point.load()
File....\python36\lib\site-packages\pkg_resources\__init__.py", line 2444, in load
    return self.resolve()
File....\python36\lib\site-packages\pkg_resources\__init__.py", line 2450, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
File....\python36\lib\site-packages\httpie_aws_auth.py", line 8, in <module>
    from httpie import ExitStatus
ImportError: cannot import name 'ExitStatus'

No issues with HTTPie v1.0.3

Output is not colored

Hello,

I am not sure this has to do with the plugin, but there seems to be some correlation, so apologies if this is the wrong place to raise this issue.

One of the things I love about HTTPie is the colored output. But for some reason the output of requests using --auth-type=jwt are not colorized. I was wondering if this is a missing feature, a bug or silly me doing something wrong.

image

Invalid syntax error

Installation output

❯ pip install httpie
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support                                                                                                                                          
Defaulting to user installation because normal site-packages is not writeable
Collecting httpie
  Using cached httpie-2.0.0-py2.py3-none-any.whl (64 kB)
Requirement already satisfied: requests>=2.22.0 in ./.local/lib/python2.7/site-packages (from httpie) (2.22.0)
Requirement already satisfied: Pygments>=2.5.2 in ./.local/lib/python2.7/site-packages (from httpie) (2.5.2)
Requirement already satisfied: certifi>=2017.4.17 in ./.local/lib/python2.7/site-packages (from requests>=2.22.0->httpie) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./.local/lib/python2.7/site-packages (from requests>=2.22.0->httpie) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in ./.local/lib/python2.7/site-packages (from requests>=2.22.0->httpie) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./.local/lib/python2.7/site-packages (from requests>=2.22.0->httpie) (1.25.8)
Installing collected packages: httpie
Successfully installed httpie-2.0.0

❯ pip install httpie-jwt-auth
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Collecting httpie-jwt-auth
  Using cached httpie_jwt_auth-0.3.0-py2.py3-none-any.whl (8.3 kB)
Requirement already satisfied: httpie>=0.9.7 in ./.local/lib/python2.7/site-packages (from httpie-jwt-auth) (2.0.0)
Requirement already satisfied: requests>=2.22.0 in ./.local/lib/python2.7/site-packages (from httpie>=0.9.7->httpie-jwt-auth) (2.22.0)
Requirement already satisfied: Pygments>=2.5.2 in ./.local/lib/python2.7/site-packages (from httpie>=0.9.7->httpie-jwt-auth) (2.5.2)
Requirement already satisfied: certifi>=2017.4.17 in ./.local/lib/python2.7/site-packages (from requests>=2.22.0->httpie>=0.9.7->httpie-jwt-auth) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./.local/lib/python2.7/site-packages (from requests>=2.22.0->httpie>=0.9.7->httpie-jwt-auth) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in ./.local/lib/python2.7/site-packages (from requests>=2.22.0->httpie>=0.9.7->httpie-jwt-auth) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./.local/lib/python2.7/site-packages (from requests>=2.22.0->httpie>=0.9.7->httpie-jwt-auth) (1.25.8)
Installing collected packages: httpie-jwt-auth
Successfully installed httpie-jwt-auth-0.3.0

Test

❯ http --auth-type=jwt --auth="token" 127.0.0.1:32769
Traceback (most recent call last):
  File "/home/user/.local/bin/http", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python2.7/site-packages/httpie/__main__.py", line 10, in main
    from .core import main
  File "/home/user/.local/lib/python2.7/site-packages/httpie/core.py", line 21
    args: List[Union[str, bytes]] = sys.argv,
        ^
SyntaxError: invalid syntax


❯ python --version
Python 2.7.17

Authorization JWT like in curl

Hi,
I'm using django + djangorestframework + djangorestframework-jwt
In curl I can get the articles list with the following command:
curl -H "Authorization: JWT <token>" http://127.0.0.1:8000/api/articles/
Is there a way to do it with httpie-jwt-auth?
I tried the following command with no success:
http --auth-type=jwt --auth="<token>" http://127.0.0.1:8000/api/articles/ -h

HTTP/1.0 401 Unauthorized
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Server: WSGIServer/0.2 CPython/3.4.4
Vary: Accept, Cookie
WWW-Authenticate: JWT realm="api"
X-Frame-Options: SAMEORIGIN

allow to override default auth prefix `Bearer` with env var

as I'm working on a client project that support JWT with auth prefix of JWT not Bearer, we should allow override this (by environment var JWT_AUTH_PREFIX or an optional option --auth-prefix=XXX)

optional option should override environment var

If not setting, default auth prefix Bearer should be used.

docs updated with flask_jwt

I was having an issue with using this extension in a flask app.
http :5000/secret --auth-type=jwt --auth="Authorization: JWT "
Tried a lot of things. Ultimately this worked
JWT_AUTH_PREFIX=JWT JWT_AUTH_TOKEN= http :5000/secret --auth-type=jwt -v
Thought this may be helpful for someone who is having an issue.
Note: I did not use && between the environmental variables as was mentioned in the docs.

add acceptance (e2e) tests

add acceptance tests to make sure it works as expected.

  • make sure --auth-type=jwt is available
  • make sure request headers should be valid, especially Authorization header when send jwt auth requests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.