Beispiel #1
0
def create_token(user):
    """
    Create a JSON Web Token (JWT) for the specified user.

    :param User user: an arkOS user
    :returns: JSON Web Token (JWT)
    :rtype: str
    """
    iat = systemtime.get_unix_time()
    try:
        offset = systemtime.get_offset()
        if offset < -3600 or offset > 3600:
            systemtime.set_datetime()
            iat = systemtime.get_unix_time()
    except:
        twarn = ("System time is not accurate or could not be verified."
                 " Access tokens will not expire.")
        logger.warning("System", twarn)
        iat = None
    payload = {
        "uid": user.name,
        "ufn": user.first_name,
        "uln": user.last_name,
    }
    if iat:
        payload["iat"] = iat
        payload["exp"] = iat + config.get("genesis", "token_valid_for", 3600)
    tjwss = TimedJSONWebSignatureSerializer(
        secret_key=current_app.config["SECRET_KEY"],
        expires_in=config.get("genesis", "token_valid_for", 3600),
        algorithm_name="HS256")
    return tjwss.dumps(payload).decode("utf-8")
Beispiel #2
0
    def update_expiry(self, nexpiry):
        """
        Update shared file expiry time.

        :param nexpiry: datetime representing expiry date/time; 0 for never
        """
        if nexpiry is False:
            self.expires = 0
        else:
            self.expires = systemtime.get_unix_time(nexpiry)
Beispiel #3
0
def create_token(user):
    iat = systemtime.get_unix_time()
    try:
        offset = systemtime.get_offset()
        if offset < -3600 or offset > 3600:
            systemtime.set_datetime()
            iat = systemtime.get_unix_time()
    except:
        current_app.logger.warning("System time is not accurate or could not be verified. Access tokens will not expire.")
        iat = None
    payload = {
        "uid": user.name,
        "ufn": user.first_name,
        "uln": user.last_name,
    }
    if iat: 
        payload["iat"] = iat
        payload["exp"] = iat + config.get("genesis", "token_valid_for", 3600)
    tjwss = TimedJSONWebSignatureSerializer(secret_key=current_app.config["SECRET_KEY"],
        expires_in=config.get("genesis", "token_valid_for", 3600), 
        algorithm_name="HS256")
    return tjwss.dumps(payload).decode("utf-8")
Beispiel #4
0
 def update_expiry(self, nexpiry):
     if nexpiry == False:
         self.expires = 0
     else:
         self.expires = systemtime.get_unix_time(nexpiry)
Beispiel #5
0
 def is_expired(self):
     return (self.expires != 0 and self.expires < systemtime.get_unix_time())
Beispiel #6
0
 def is_expired(self):
     """Return True if the object is already expired."""
     now = systemtime.get_unix_time()
     return (self.expires != 0 and self.expires < now)