adminapi.request.calc_security_token - python examples

Here are the examples of the python api adminapi.request.calc_security_token taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

0 View Complete Implementation : decorators.py
Copyright MIT License
Author : innogames
def authenticate_app_psk(app_id, security_token, timestamp, body):
    """Authenticate request HMAC

    Recreate the security token using the timestamp and body from the request.
    Check if the client send the same security token.

    If they don't match the client doesn't have the correct auth token and we
    raise PermissionDenied.

    Return the app the user authenticated to
    """
    try:
        app = Application.objects.get(app_id=app_id)
    except Application.DoesNotExist as error:
        raise PermissionDenied(error)

    expected_proof = calc_security_token(app.auth_token, timestamp, body)
    if not constant_time_compare(expected_proof, security_token):
        raise PermissionDenied('Invalid security token')

    return app