Пример #1
0
def validate_token(token_in_headers, token_in_query_params):
    """
    Validate the provided authentication token.

    :param token_in_headers: Authentication token provided via headers.
    :type token_in_headers: ``str``

    :param token_in_query_params: Authentication token provided via query params.
    :type token_in_query_params: ``str``

    :return: TokenDB object on success.
    :rtype: :class:`.TokenDB`
    """
    if not token_in_headers and not token_in_query_params:
        LOG.audit('Token is not found in header or query parameters.')
        raise exceptions.TokenNotProvidedError('Token is not provided.')

    if token_in_headers:
        LOG.audit('Token provided in headers')

    if token_in_query_params:
        LOG.audit('Token provided in query parameters')

    token_string = token_in_headers or token_in_query_params
    token = Token.get(token_string)

    if token.expiry <= isotime.add_utc_tz(datetime.datetime.utcnow()):
        # TODO: purge expired tokens
        LOG.audit('Token with id "%s" has expired.' % (token.id))
        raise exceptions.TokenExpiredError('Token has expired.')

    LOG.audit('Token with id "%s" is validated.' % (token.id))
    return token
Пример #2
0
def validate_token(token_in_headers, token_in_query_params):
    """
    Validate the provided authentication token.

    :param token_in_headers: Authentication token provided via headers.
    :type token_in_headers: ``str``

    :param token_in_query_params: Authentication token provided via query params.
    :type token_in_query_params: ``str``

    :return: TokenDB object on success.
    :rtype: :class:`.TokenDB`
    """
    if not token_in_headers and not token_in_query_params:
        LOG.audit('Token is not found in header or query parameters.')
        raise exceptions.TokenNotProvidedError('Token is not provided.')

    if token_in_headers:
        LOG.audit('Token provided in headers')

    if token_in_query_params:
        LOG.audit('Token provided in query parameters')

    token_string = token_in_headers or token_in_query_params
    token = Token.get(token_string)

    if token.expiry <= date_utils.get_datetime_utc_now():
        # TODO: purge expired tokens
        LOG.audit('Token with id "%s" has expired.' % (token.id))
        raise exceptions.TokenExpiredError('Token has expired.')

    LOG.audit('Token with id "%s" is validated.' % (token.id))
    return token
Пример #3
0
def delete_token(token):
    try:
        token_db = Token.get(token)
        return Token.delete(token_db)
    except TokenNotFoundError:
        pass
    except Exception:
        raise
Пример #4
0
 def test_delete_token(self):
     token = access.create_token(USERNAME)
     access.delete_token(token.token)
     try:
         token = Token.get(token.token)
         self.assertTrue(False, 'Delete failed was expected to pass.')
     except TokenNotFoundError:
         self.assertTrue(True)
Пример #5
0
 def test_delete_token(self):
     token = access.create_token(USERNAME)
     access.delete_token(token.token)
     try:
         token = Token.get(token.token)
         self.assertTrue(False, 'Delete failed was expected to pass.')
     except TokenNotFoundError:
         self.assertTrue(True)
Пример #6
0
def delete_token(token):
    try:
        token_db = Token.get(token)
        return Token.delete(token_db)
    except TokenNotFoundError:
        pass
    except Exception:
        raise
Пример #7
0
Файл: auth.py Проект: Bala96/st2
def validate_token(token_string):
    """
    Validate the provided authentication token.

    :param token_string: Authentication token provided.
    :type token_string: ``str``

    :return: TokenDB object on success.
    :rtype: :class:`.TokenDB`
    """
    token = Token.get(token_string)

    if token.expiry <= date_utils.get_datetime_utc_now():
        # TODO: purge expired tokens
        LOG.audit('Token with id "%s" has expired.' % (token.id))
        raise exceptions.TokenExpiredError('Token has expired.')

    LOG.audit('Token with id "%s" is validated.' % (token.id))

    return token
Пример #8
0
def validate_token(token_string):
    """
    Validate the provided authentication token.

    :param token_string: Authentication token provided.
    :type token_string: ``str``

    :return: TokenDB object on success.
    :rtype: :class:`.TokenDB`
    """
    token = Token.get(token_string)

    if token.expiry <= date_utils.get_datetime_utc_now():
        # TODO: purge expired tokens
        LOG.audit('Token with id "%s" has expired.' % (token.id))
        raise exceptions.TokenExpiredError('Token has expired.')

    LOG.audit('Token with id "%s" is validated.' % (token.id))

    return token