def check_authorizer_token()

in source/token-authorizer/chalice/app.py [0:0]


def check_authorizer_token(token, resource):
    """
    This function is responsible for checking tokens and
    returning a policy for the custom authorizer for the resource
    """
    response = {
        "principalId": "denied",
        "policyDocument": {
            "Version": "2012-10-17",
            "Statement": []
        }
    }
    statement = {
        "Action": "execute-api:Invoke",
        "Effect": "Deny",
        "Resource": resource
    }
    response["policyDocument"]["Statement"].append(statement)
    claims = verify_token(token)
    if claims:
        principal_id = claims.get("sub", 'approved')
        response["principalId"] = principal_id
        statement["Effect"] = "Allow"
    print(json.dumps(response))
    return response