This repository has been archived by the owner on Nov 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
111 additions
and
6 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,36 @@ | ||
#!/usr/bin/env python | ||
from flask.sessions import SecureCookieSessionInterface | ||
from itsdangerous import URLSafeTimedSerializer | ||
|
||
# Adapted from here: https://gist.github.com/aescalana/7e0bc39b95baa334074707f73bc64bfe | ||
|
||
|
||
class SimpleSecureCookieSessionInterface(SecureCookieSessionInterface): | ||
# Override method | ||
# Take secret_key instead of an instance of a Flask app | ||
def get_signing_serializer(self, secret_key): | ||
if not secret_key: | ||
return None | ||
signer_kwargs = dict( | ||
key_derivation=self.key_derivation, | ||
digest_method=self.digest_method | ||
) | ||
return URLSafeTimedSerializer(secret_key, salt=self.salt, | ||
serializer=self.serializer, | ||
signer_kwargs=signer_kwargs) | ||
|
||
|
||
def decodeFlaskCookie(secret_key, cookieValue): | ||
sscsi = SimpleSecureCookieSessionInterface() | ||
signingSerializer = sscsi.get_signing_serializer(secret_key) | ||
return signingSerializer.loads(cookieValue) | ||
|
||
|
||
# Keep in mind that flask uses unicode strings for the | ||
# dictionary keys | ||
def encodeFlaskCookie(secret_key, cookieDict): | ||
sscsi = SimpleSecureCookieSessionInterface() | ||
signingSerializer = sscsi.get_signing_serializer(secret_key) | ||
return signingSerializer.dumps(cookieDict) | ||
|
||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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