Created
July 14, 2017 10:05
-
-
Save arujit/0833c6e7497a7112e866a17c944c56fa to your computer and use it in GitHub Desktop.
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
import jwt | |
class JwtBase(object): | |
_instance = None | |
def __new__(class_, *args, **kwargs): | |
if not isinstance(class_._instance, class_): | |
class_._instance = object.__new__(class_, *args, **kwargs) | |
return class_._instance | |
@classmethod | |
def initalize(cls, private_path, public_path ): | |
try: | |
cls._publickey_file = open(public_path, "r") | |
cls._privatekey_file = open(private_path, "r") | |
except: | |
raise IOError | |
else: | |
print cls._privatekey_file | |
cls._public_key = cls._publickey_file.read() | |
cls._private_key = cls._privatekey_file.read() | |
class Jwt(JwtBase): | |
@classmethod | |
def encoding(cls, payload): | |
return jwt.encode(payload, cls._private_key, algorithm="RS512") | |
@classmethod | |
def decoding(cls, encoded_token): | |
return jwt.decode(encoded_token, cls._public_key, verify=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment