rs / eve-auth-jwt Goto Github PK
View Code? Open in Web Editor NEWEve OAuth 2.0 JWT token validation authentication module
License: MIT License
Eve OAuth 2.0 JWT token validation authentication module
License: MIT License
the JWTAuth extend the BasicAuth what mean that it should implement the check_auth method, which is
not implemented.
when i add it in my module : app = Eve(auth=JWTAuth), i get the following error:
{
"status": "ERR",
"error": {
"message": "Please provide proper credentials",
"code": 401
}
}
My Question: is this module uptodate? when yes, how it should be used
I want to use it in my project and am wondering if this project is deprecated.
Here is my contribution, if you want to join in your project.
# -*- coding: utf-8 -*-
import datetime
import jwt
from jwt.algorithms import RSAAlgorithm
import logging
logger = logging.getLogger(__name__)
class Token(object):
"""Usage:
t = Token()
str_token = t.generate(payload_dict, path_to_private_key, expiration_in_seconds)
payload_dict = t.verify(str_token, path_to_public_key)
"""
def verify(self, token, prublic_key_file):
""" Verify token. """
algo = RSAAlgorithm(RSAAlgorithm.SHA256)
logger.debug("reading pub shakey")
with open(prublic_key_file, 'r') as f:
shakey = algo.prepare_key(f.read())
logger.debug(shakey)
payload = jwt.decode(token, key=shakey)
logger.debug("payload = {0}".format(payload))
return payload
def generate(self, payload, private_key_file, expiration=600):
""" Generate token. """
algo = RSAAlgorithm(RSAAlgorithm.SHA256)
with open(private_key_file, 'r') as f:
shakey = algo.prepare_key(f.read())
payload.update({
'exp': datetime.datetime.utcnow() + datetime.timedelta(seconds=expiration)
})
logger.debug("payload = {0}".format(payload))
token = jwt.encode(payload, key=shakey, algorithm='RS256')
logger.debug("token generated = {0}".format(token.decode('ascii')))
return token.decode('ascii')
Would it be possible to create a new release of eve-auth-jwt? The last release was over 1.5 years ago :)
check_token fails for endpoints without DOMAIN entry, this is for example the case if you set SCHEMA_ENDPOINT, on the root /schema it will always fail because this resource_conf = config.DOMAIN[resource]
it is a pretty easy fix, I changed it to this resource_conf = config.DOMAIN.get(resource, {})
.
I fixed it on my own fork, but did not add unit tests, if you accept pr, i will make one to fix this. I am leaving this for reference here, because it seems like the repo is not being updated lately.
Cheers,
How can we create a simple token, using eve and jwt?
What fields are required?
Maybe implementing a route like /api/auth directly in the eve-auth-jwt would be a nice feature?
Thanks!
The authenticate method is returning:
('WWW-Authenticate', 'Bearer realm="eve_auth_jwt", error="invalid_token"'): ('Content-Type', 'text/html; charset=utf-8')
instead of
WWW-Authenticate: Bearer realm="eve_auth_jwt", error="invalid_token"
which, apart of being an invalid header, makes gunicorn fail with HTTP error code 400, and the message "Invalid HTTP header name".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.