How to use PyJWT - 2 common examples

To help you get started, we’ve selected a few PyJWT examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bbsan2k / plugin.video.f1tv / resources / lib / F1TVParser / AccountManager.py View on Github external
def __createAuthorization__(self):
        if self.session_token is not None:
            # Try to load a cached social token
            try:
                social_token_store = Store("app://tokens/social/{username}".format(username=self.username))
                social_tokens = social_token_store.retrieve()
                if len(social_tokens):
                    for cached_token in social_tokens:
                        cached_token_expiration_time = datetime.fromtimestamp(jwt.decode(cached_token, verify=False)['exp'])

                        token_validity_time_remaining = cached_token_expiration_time - datetime.now()

                        if token_validity_time_remaining.total_seconds() <= 60 * 60 * 24:
                            self.__requestSocialToken()
                        else:
                            self.session.headers["Authorization"] = "JWT " + cached_token
                else:
                    self.__requestSocialToken()

            except:
                self.__requestSocialToken()
github bbsan2k / plugin.video.f1tv / resources / lib / F1TVParser / AccountManager.py View on Github external
def __createSession__(self):
        # Try to load a cached token
        try:
            session_token_store = Store("app://tokens/session/{username}".format(username=self.username))
            session_tokens = session_token_store.retrieve()
            self.session_token = None
            if len(session_tokens):
                for cached_token in session_tokens:
                    cached_token_expiration_time = datetime.fromtimestamp(jwt.decode(cached_token, verify=False)['exp'])

                    token_validity_time_remaining = cached_token_expiration_time - datetime.now()

                    if token_validity_time_remaining.total_seconds() <= 60 * 60 * 24:
                        self.session_token = None
                    else:
                        self.session_token = cached_token
            else:
                self.session_token = None
        except:
            self.session_token = None

        if self.session_token is None:
            self.__requestSessionToken()
        else:
            pass

PyJWT

JSON Web Token implementation in Python

MIT
Latest version published 5 days ago

Package Health Score

94 / 100
Full package analysis

Popular PyJWT functions