-
-
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 #195 from ahopkins/split-cookie
Split cookie
- Loading branch information
Showing
28 changed files
with
343 additions
and
70 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
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,56 @@ | ||
""" | ||
This is taken from "Simple Usage" page in the docs: | ||
http://sanic-jwt.readthedocs.io/en/latest/pages/simpleusage.html | ||
""" | ||
|
||
from sanic import Sanic | ||
from sanic_jwt import exceptions, initialize | ||
|
||
|
||
class User: | ||
def __init__(self, id, username, password): | ||
self.user_id = id | ||
self.username = username | ||
self.password = password | ||
|
||
def __repr__(self): | ||
return "User(id='{}')".format(self.user_id) | ||
|
||
def to_dict(self): | ||
return {"user_id": self.user_id, "username": self.username} | ||
|
||
|
||
users = [User(1, "user1", "abcxyz"), User(2, "user2", "abcxyz")] | ||
|
||
username_table = {u.username: u for u in users} | ||
userid_table = {u.user_id: u for u in users} | ||
|
||
|
||
async def authenticate(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.") | ||
|
||
user = username_table.get(username, None) | ||
if user is None: | ||
raise exceptions.AuthenticationFailed("User not found.") | ||
|
||
if password != user.password: | ||
raise exceptions.AuthenticationFailed("Password is incorrect.") | ||
|
||
return user | ||
|
||
|
||
app = Sanic() | ||
initialize( | ||
app, | ||
authenticate=authenticate, | ||
cookie_set=True, | ||
cookie_split=True, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host="127.0.0.1", port=8888) |
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from datetime import datetime, timedelta | ||
|
||
import jwt | ||
|
||
from freezegun import freeze_time | ||
|
||
|
||
|
Oops, something went wrong.