Esempio n. 1
0
def get_user_token_auth_hash(user, expires_timestamp):
    """Generates the hash portion of a user token-auth token
    """
    encrypted_uid = encrypt_uid(user)
    salt = user.profile.salt
    key = htk_setting('HTK_USER_TOKEN_AUTH_ENCRYPTION_KEY')

    prehash = '%s|%s|%s|%s' % (
        encrypted_uid,
        salt,
        expires_timestamp,
        key,
    )

    hashed = hashlib.sha256(prehash).hexdigest()

    return hashed
Esempio n. 2
0
def get_user_token_auth_hash(user, expires_timestamp):
    """Generates the hash portion of a user token-auth token
    """
    encrypted_uid = encrypt_uid(user)
    salt = user.profile.salt
    key = htk_setting('HTK_USER_TOKEN_AUTH_ENCRYPTION_KEY')

    prehash = '%s|%s|%s|%s' % (
        encrypted_uid,
        salt,
        expires_timestamp,
        key,
    )

    hashed = hashlib.sha256(prehash.encode()).hexdigest()

    return hashed
Esempio n. 3
0
def get_user_token_auth_token(user, expires_minutes=None):
    """Returns the token to auth/log in the `user`

    Typically would want to include the generated token in an email
    so that that user can directly log in to the app.
    """
    encrypted_uid = encrypt_uid(user)

    expires_minutes = expires_minutes if expires_minutes else htk_setting('HTK_USER_TOKEN_AUTH_EXPIRES_MINUTES')
    expires = utcnow() + datetime.timedelta(minutes=expires_minutes)
    expires_timestamp = datetime_to_unix_time(expires)

    hashed = get_user_token_auth_hash(user, expires_timestamp)

    data = {
        'user' : encrypted_uid,
        'expires' : expires_timestamp,
        'hash' : hashed,
    }

    token = base64.b64encode(json.dumps(data))
    return token
Esempio n. 4
0
def get_user_token_auth_token(user, expires_minutes=None):
    """Returns the token to auth/log in the `user`

    Typically would want to include the generated token in an email
    so that that user can directly log in to the app.
    """
    encrypted_uid = encrypt_uid(user)

    expires_minutes = expires_minutes if expires_minutes else htk_setting('HTK_USER_TOKEN_AUTH_EXPIRES_MINUTES')
    expires = utcnow() + datetime.timedelta(minutes=expires_minutes)
    expires_timestamp = datetime_to_unix_time(expires)

    hashed = get_user_token_auth_hash(user, expires_timestamp)

    data = {
        'user' : encrypted_uid,
        'expires' : expires_timestamp,
        'hash' : hashed,
    }

    token = base64.b64encode(json.dumps(data).encode('utf-8')).decode('utf-8')
    return token
Esempio n. 5
0
 def get_unfollow_uri(self):
     unfollow_user_url_name = htk_setting('HTK_API_USERS_UNFOLLOW_URL_NAME')
     unfollow_uri = reverse(unfollow_user_url_name, args=(encrypt_uid(self.user),))
     return unfollow_uri
Esempio n. 6
0
 def get_unfollow_uri(self):
     unfollow_user_url_name = htk_setting('HTK_API_USERS_UNFOLLOW_URL_NAME')
     unfollow_uri = reverse(unfollow_user_url_name,
                            args=(encrypt_uid(self.user), ))
     return unfollow_uri