示例#1
0
    def create(self,
               user,
               password=None,
               expires=knox_settings.TOKEN_TTL,
               return_instance=False):
        token = crypto.create_token_string()
        salt = crypto.create_salt_string()
        digest = crypto.hash_token(token, salt)

        encrypted = None
        if password:
            fernet = Fernet(crypto.derive_fernet_key(password, salt))
            encrypted = fernet.encrypt(encoding.force_bytes(token))

        if expires is not None:
            expires = timezone.now() + expires

        auth_token = super(AuthTokenManager, self).create(digest=digest,
                                                          salt=salt,
                                                          encrypted=encrypted,
                                                          user=user,
                                                          expires=expires)
        if return_instance:
            return auth_token
        return token  # Note only the token - not the AuthToken object - is returned
示例#2
0
    def create(self, user, time=knox_settings.DEFAULT_TOKEN_TTL, use=knox_settings.DEFAULT_TOKEN_USE):
        token = crypto.create_token_string()
        salt = crypto.create_salt_string()
        digest = crypto.hash_token(token, salt)

        auth_token = super(AuthTokenManager, self).create(digest=digest, salt=salt, user=user, time=time, use=use)
        return token # Note only the token - not the AuthToken object - is returned
    def create_and_return(self, **kwargs):
        token = crypto.create_token_string()
        salt = crypto.create_salt_string()
        digest = crypto.hash_token(token, salt)

        expires = kwargs.get('expires', None)
        if expires is not None:
            expires = timezone.now() + expires

        kwargs.update({
            'digest': digest,
            'salt': salt,
            'expires': expires,
            'token_key': token[:CONSTANTS.TOKEN_KEY_LENGTH]
        })

        auth_token = super(AuthTokenManager, self).create(**kwargs)
        auth_token.token = token

        return auth_token

        kwargs.update({
            'digest': digest,
            'salt': salt,
            'expires': expires
        })

        auth_token = super(AuthTokenManager, self).create(**kwargs)
        auth_token.token = token

        return auth_token
示例#4
0
    def create_unsafe(self, user, expires=knox_settings.TOKEN_TTL):
        token = crypto.create_token_string()
        salt = crypto.create_salt_string()
        digest = crypto.hash_token(token, salt)

        if expires is not None:
             expires = timezone.now() + expires

        auth_token = super(AuthTokenManager, self).create(digest=digest, salt=salt, user=user, expires=expires)
        return auth_token, token # Note only the token - not the AuthToken object - is returned
示例#5
0
    def create(self, user, expires=knox_settings.TOKEN_TTL):
        token = crypto.create_token_string()
        salt = crypto.create_salt_string()
        digest = crypto.hash_token(token, salt)

        if expires is not None:
             expires = timezone.now() + expires

        auth_token = super(AuthTokenManager, self).create(digest=digest, salt=salt, user=user, expires=expires, token_slice=token[:16])
        return token # Note only the token - not the AuthToken object - is returned
示例#6
0
    def create(self, user, expiry=knox_settings.TOKEN_TTL):
        token = crypto.create_token_string()
        salt = crypto.create_salt_string()
        digest = crypto.hash_token(token, salt)

        if expiry is not None:
            expiry = timezone.now() + expiry

        instance = super(AuthTokenManager, self).create(
            token_key=token[:CONSTANTS.TOKEN_KEY_LENGTH], digest=digest,
            salt=salt, user=user, expiry=expiry)
        return instance, token
示例#7
0
    def create(self, user, expires=knox_settings.TOKEN_TTL):
        token = crypto.create_token_string()
        salt = crypto.create_salt_string()
        digest = crypto.hash_token(token, salt)

        if expires is not None:
            expires = timezone.now() + expires

        super(AuthTokenManager, self).create(
            token_key=token[:CONSTANTS.TOKEN_KEY_LENGTH], digest=digest,
            salt=salt, user=user, expires=expires)
        # Note only the token - not the AuthToken object - is returned
        return token
示例#8
0
    def create(self, user, expiry=knox_settings.TOKEN_TTL):
        token = crypto.create_token_string()
        digest = crypto.hash_token(token)

        if expiry is not None:
            expiry = timezone.now() + expiry

        instance = super(AuthTokenManager, self).create(
            token_key=token[:CONSTANTS.TOKEN_KEY_LENGTH],
            digest=digest,
            user=user,
            expiry=expiry)
        return instance, token
示例#9
0
    def create(self, user, expires=knox_settings.TOKEN_TTL):
        token = crypto.create_token_string()
        salt = crypto.create_salt_string()
        digest = crypto.hash_token(token, salt)

        if expires is not None:
            expires = timezone.now() + expires

        super(AuthTokenManager,
              self).create(token_key=token[:CONSTANTS.TOKEN_KEY_LENGTH],
                           digest=digest,
                           salt=salt,
                           user=user,
                           expires=expires)
        # Note only the token - not the AuthToken object - is returned
        return token
示例#10
0
    def create(
            self, user, password=None, expires=knox_settings.TOKEN_TTL,
            return_instance=False):
        token = crypto.create_token_string()
        salt = crypto.create_salt_string()
        digest = crypto.hash_token(token, salt)

        encrypted = None
        if password:
            fernet = Fernet(crypto.derive_fernet_key(password, salt))
            encrypted = fernet.encrypt(encoding.force_bytes(token))

        if expires is not None:
             expires = timezone.now() + expires

        auth_token = super(AuthTokenManager, self).create(
            digest=digest, salt=salt, encrypted=encrypted,
            user=user, expires=expires)
        if return_instance:
            return auth_token
        return token # Note only the token - not the AuthToken object - is returned