コード例 #1
0
ファイル: auth.py プロジェクト: jimtyhurst/h
def debug_token(request):
    if not request.auth_token:
        raise OAuthTokenError(
            "Bearer token is missing in Authorization HTTP header",
            "missing_token")

    svc = request.find_service(name="auth_token")
    token = svc.validate(request.auth_token)
    if token is None:
        raise OAuthTokenError("Bearer token does not exist or is expired",
                              "missing_token")

    token = svc.fetch(request.auth_token)
    return _present_debug_token(token)
コード例 #2
0
 def test_it_skips_description_when_empty(self, pyramid_request):
     context = OAuthTokenError("", "invalid_request")
     result = views.api_token_error(context, pyramid_request)
     assert "error_description" not in result
コード例 #3
0
 def test_it_returns_error_description(self, pyramid_request):
     context = OAuthTokenError("error description", "error_type")
     result = views.api_token_error(context, pyramid_request)
     assert result["error_description"] == "error description"
コード例 #4
0
 def test_it_returns_the_error(self, pyramid_request):
     context = OAuthTokenError("", "error_type")
     result = views.api_token_error(context, pyramid_request)
     assert result["error"] == "error_type"
コード例 #5
0
 def test_it_sets_the_response_status_code(self, pyramid_request):
     context = OAuthTokenError("the error message", "error_type")
     views.api_token_error(context, pyramid_request)
     assert pyramid_request.response.status_code == 401