-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from ahopkins/dev
Version 1.2.0 - 2018-11-08
- Loading branch information
Showing
58 changed files
with
1,325 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,8 @@ source = | |
tests | ||
|
||
[run] | ||
source = | ||
sanic_jwt | ||
tests | ||
source = sanic_jwt | ||
omit = tests | ||
branch = True | ||
|
||
[report] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,48 @@ | ||
# Config file for automatic testing at travis-ci.org | ||
|
||
language: python | ||
|
||
python: | ||
# - "3.7-dev" | ||
- "3.6" | ||
- "3.5" | ||
# - "pypy" | ||
|
||
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors | ||
dist: xenial | ||
sudo: true | ||
env: | ||
global: | ||
- LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so | ||
- SEGFAULT_SIGNALS=all | ||
- DEVELOPMENT=false | ||
matrix: | ||
fast_finish: true | ||
include: | ||
- python: "3.5" | ||
env: TOXENV=py35 | ||
- python: "3.6" | ||
env: TOXENV=py36 | ||
- python: "3.7" | ||
env: TOXENV=py37 | ||
# - python: "3.6" | ||
# env: TOXENV=check | ||
cache: | ||
directories: | ||
- $HOME/.cache/pip | ||
before_install: | ||
- python --version | ||
- uname -a | ||
- lsb_release -a | ||
- pip install codecov | ||
install: | ||
- pip install -r example/requirements.txt | ||
|
||
# command to run tests, e.g. python setup.py test | ||
- pip install tox | ||
- virtualenv --version | ||
- easy_install --version | ||
- pip --version | ||
- tox --version | ||
script: | ||
- python setup.py test | ||
|
||
- tox -v | ||
after_success: | ||
- coverage xml | ||
- python-codacy-coverage -r coverage.xml | ||
- codecov | ||
|
||
env: | ||
- DEVELOPMENT=false | ||
- tox -e report | ||
- coverage xml | ||
- python-codacy-coverage -r coverage.xml | ||
- codecov | ||
after_failure: | ||
- more .tox/log/* | cat | ||
- more .tox/*/log/* | cat | ||
notifications: | ||
email: | ||
on_success: never | ||
on_failure: always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sphinx==1.8.1 | ||
sphinx_rtd_theme==0.4.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from sanic import Sanic | ||
from sanic.response import json | ||
|
||
from sanic_jwt import Authentication, exceptions, Initialize | ||
|
||
|
||
class MyAuthentication(Authentication): | ||
|
||
async def authenticate(self, request, *args, **kwargs): | ||
username = request.json.get("username", None) | ||
password = request.json.get("password", None) | ||
|
||
if not username or not password: | ||
raise exceptions.AuthenticationFailed( | ||
"Missing username or password." | ||
) | ||
|
||
return {"user_id": 1} | ||
|
||
async def store_refresh_token( | ||
self, user_id, refresh_token, *args, **kwargs | ||
): | ||
key = "refresh_token_{user_id}".format(user_id=user_id) | ||
self.app.my_cache[key] = refresh_token | ||
|
||
async def retrieve_refresh_token(self, user_id, *args, **kwargs): | ||
key = "refresh_token_{user_id}".format(user_id=user_id) | ||
token = self.app.my_cache.get(key, None) | ||
return token | ||
|
||
async def retrieve_user(self, request, payload, *args, **kwargs): | ||
if payload: | ||
user_id = payload.get("user_id", None) | ||
return {"user_id": user_id} | ||
|
||
else: | ||
return None | ||
|
||
|
||
# elsewhere in the universe ... | ||
if __name__ == "__main__": | ||
app = Sanic(__name__) | ||
app.my_cache = {} | ||
|
||
sanicjwt = Initialize( | ||
app, authentication_class=MyAuthentication, refresh_token_enabled=True | ||
) | ||
|
||
@app.route("/") | ||
async def helloworld(request): | ||
return json({"hello": "world"}) | ||
|
||
@app.route("/protected") | ||
@sanicjwt.protected() | ||
async def protected_request(request): | ||
return json({"protected": True}) | ||
|
||
# this route is for demonstration only | ||
|
||
@app.route("/cache") | ||
@sanicjwt.protected() | ||
async def protected_cache(request): | ||
return json(request.app.my_cache) | ||
|
||
app.run() |
Oops, something went wrong.