Exemplo n.º 1
0
def authz_error(error, descr=None, status_code=400):
    response = AuthorizationErrorResponse(error=error)
    if descr:
        response["error_description"] = descr

    return Response(response.to_json(), content="application/json",
                    status="400 Bad Request")
Exemplo n.º 2
0
    def _authz_error(error, descr=None):

        response = AuthorizationErrorResponse(error=error)
        if descr:
            response["error_description"] = descr

        return Response(response.to_json(), content="application/json",
                        status="400 Bad Request")
Exemplo n.º 3
0
    def test_parse_authz_access_denied(self):
        sid, loc = self.consumer.begin("http://localhost:8087",
                                       "http://localhost:8088/authorization")

        atr = AuthorizationErrorResponse(error="access_denied", state=sid)

        with pytest.raises(AuthzError):
            self.consumer.handle_authorization_response(
                query=atr.to_urlencoded())
Exemplo n.º 4
0
    def test_parse_authz_access_denied(self):
        sid, loc = self.consumer.begin("http://localhost:8087",
                                       "http://localhost:8088/authorization")

        atr = AuthorizationErrorResponse(error="access_denied", state=sid)

        with pytest.raises(AuthzError):
            self.consumer.handle_authorization_response(
                query=atr.to_urlencoded())
Exemplo n.º 5
0
def redirect_authz_error(error, redirect_uri, descr=None, state="", return_type=None):
    err = AuthorizationErrorResponse(error=error)
    if descr:
        err["error_description"] = descr
    if state:
        err["state"] = state
    if return_type is None or return_type == ["code"]:
        location = err.request(redirect_uri)
    else:
        location = err.request(redirect_uri, True)
    return SeeOther(location)
Exemplo n.º 6
0
 def _redirect_authz_error(error, redirect_uri, descr=None, state="",
                           return_type=None):
     err = AuthorizationErrorResponse(error=error)
     if descr:
         err["error_description"] = descr
     if state:
         err["state"] = state
     if return_type is None or return_type == ["code"]:
         location = err.request(redirect_uri)
     else:
         location = err.request(redirect_uri, True)
     return SeeOther(location)
Exemplo n.º 7
0
def test_consumer_parse_authz_error():
    _session_db = {}
    cons = Consumer(_session_db, client_config=CLIENT_CONFIG,
                    server_info=SERVER_INFO, **CONSUMER_CONFIG)
    cons.debug = True

    sid, loc = cons.begin("http://localhost:8087",
                          "http://localhost:8088/authorization")

    atr = AuthorizationErrorResponse(error="access_denied", state=sid)

    QUERY_STRING = atr.to_urlencoded()

    raises(AuthzError,
           "cons.handle_authorization_response(query=QUERY_STRING)")
Exemplo n.º 8
0
 def test_extra_params(self):
     aer = AuthorizationErrorResponse(error="access_denied",
                                      error_description="brewers has a four game series",
                                      foo="bar")
     assert aer["error"] == "access_denied"
     assert aer["error_description"] == "brewers has a four game series"
     assert aer["foo"] == "bar"
Exemplo n.º 9
0
def test_consumer_parse_authz_error():
    _session_db = {}
    cons = Consumer(_session_db, client_config = CLIENT_CONFIG,
                    server_info=SERVER_INFO, **CONSUMER_CONFIG)
    cons.debug = True
    environ = BASE_ENVIRON

    _ = cons.begin(environ, start_response)

    atr = AuthorizationErrorResponse(error="access_denied", state=cons.state)
    
    environ = BASE_ENVIRON.copy()
    environ["QUERY_STRING"] = atr.to_urlencoded()

    raises(AuthzError,
           "cons.handle_authorization_response(environ, start_response)")
Exemplo n.º 10
0
def test_consumer_parse_authz_error():
    _session_db = {}
    cons = Consumer(_session_db,
                    client_config=CLIENT_CONFIG,
                    server_info=SERVER_INFO,
                    **CONSUMER_CONFIG)
    cons.debug = True

    _ = cons.begin("http://localhost:8087",
                   "http://localhost:8088/authorization")

    atr = AuthorizationErrorResponse(error="access_denied", state=cons.state)

    QUERY_STRING = atr.to_urlencoded()

    raises(AuthzError,
           "cons.handle_authorization_response(query=QUERY_STRING)")
Exemplo n.º 11
0
 def test_init(self):
     aer = AuthorizationErrorResponse(error="access_denied", state="xyz")
     assert aer["error"] == "access_denied"
     assert aer["state"] == "xyz"