Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

jhildreth/falcon-jwt-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

falcon-jwt-checker

falcon-jwt-checker is a middleware for the Falcon Python web framework. It checks all requests (except those to specified exempt routes or using a specified exempt method) for a valid jwt, rejecting those that do not have one present. It uses PyJwt to perform jwt validation.

falcon-jwt-checker merely checks for valid jwts on requests, it does not deal with issuing tokens at all. This is because I view that as a separate concern entirely, for which there are a number of possible strategies.

Installation

pip install falcon-jwt-checker

Usage

import falcon
from falcon_jwt_checker import JwtChecker

jwt_checker = JwtChecker(
    secret='secret_here', # May be a public key
    algorithm='HS256',
    exempt_routes=['/auth'], # Routes listed here will not require a jwt
    exempt_methods=['OPTIONS'], # HTTP request methods listed here will not require a jwt
    audience='api.example.com',
    leeway=30
)

app = falcon.API(middleware=[jwt_checker])

...

In responder methods, add a parameter argument for the keyword argument 'jwt_claims', e.g. **params, which is added after processing the token for endpoints that are authenticated.

class StatusResource(object):
    def on_get(self, req, resp, **params):

Tests

pytest falcon_jwt_checker

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages