Exemple #1
0
    def authorization(self, request, **kwargs):
        areq = AuthorizationRequest().from_urlencoded(request)

        if not areq.verify():
            raise OicMsgError()

        resp = HTTPResponse('OK')
        return resp
Exemple #2
0
    def test_deserialize_urlencoded_multiple_params(self):
        ar = AuthorizationRequest(
            response_type=["code"],
            client_id="foobar",
            redirect_uri="http://foobar.example.com/oaclient",
            scope=["foo", "bar"],
            state="cold")
        urlencoded = ar.to_urlencoded()
        ar2 = AuthorizationRequest().deserialize(urlencoded, "urlencoded")

        assert ar == ar2
Exemple #3
0
    def test_urlencoded_resp_type_token(self):
        ar = AuthorizationRequest(response_type=["token"],
                                  client_id="s6BhdRkqt3",
                                  redirect_uri="https://client.example.com/cb",
                                  state="xyz")

        ue = ar.to_urlencoded()
        assert query_string_compare(
            ue,
            "state=xyz&redirect_uri=https%3A%2F%2Fclient.example.com%2Fcb&response_type=token&"
            "client_id=s6BhdRkqt3")
Exemple #4
0
    def test_urlencoded_with_redirect_uri(self):
        ar = AuthorizationRequest(
            response_type=["code"],
            client_id="foobar",
            redirect_uri="http://foobar.example.com/oaclient",
            state="cold")

        ue = ar.to_urlencoded()
        assert query_string_compare(
            ue,
            "state=cold&redirect_uri=http%3A%2F%2Ffoobar.example.com%2Foaclient&"
            "response_type=code&client_id=foobar")
Exemple #5
0
    def test_json_resp_type_token(self):
        ar = AuthorizationRequest(response_type=["token"],
                                  client_id="s6BhdRkqt3",
                                  redirect_uri="https://client.example.com/cb",
                                  state="xyz")

        ue_obj = json.loads(ar.serialize(method="json"))
        expected_ue_obj = {
            "state": "xyz",
            "redirect_uri": "https://client.example.com/cb",
            "response_type": "token",
            "client_id": "s6BhdRkqt3"
        }
        assert ue_obj == expected_ue_obj
Exemple #6
0
    def test_json_multiple_params(self):
        ar = AuthorizationRequest(
            response_type=["code"],
            client_id="foobar",
            redirect_uri="http://foobar.example.com/oaclient",
            state="cold")

        ue_obj = json.loads(ar.serialize(method="json"))
        expected_ue_obj = {
            "response_type": "code",
            "state": "cold",
            "redirect_uri": "http://foobar.example.com/oaclient",
            "client_id": "foobar"
        }
        assert ue_obj == expected_ue_obj
Exemple #7
0
    def test_urlencoded_deserialize_state(self):
        txt = "scope=foo+bar&state=-11&redirect_uri=http%3A%2F%2Ffoobar" \
              ".example.com%2Foaclient&response_type=code&" \
              "client_id=foobar"

        ar = AuthorizationRequest().deserialize(txt, "urlencoded")
        assert ar["state"] == "-11"
Exemple #8
0
    def test_urlencoded_deserialize_response_type(self):
        txt = "scope=openid&state=id-6a3fc96caa7fd5cb1c7d00ed66937134&" \
              "redirect_uri=http%3A%2F%2Flocalhost%3A8087authz&response_type" \
              "=code&client_id=a1b2c3"

        ar = AuthorizationRequest().deserialize(txt, "urlencoded")
        assert ar["scope"] == ["openid"]
        assert ar["response_type"] == ["code"]
Exemple #9
0
    def test_json_serizalize_deserialize_multiple_params(self):
        argv = {
            "scope": ["openid"],
            "state": "id-b0be8bb64118c3ec5f70093a1174b039",
            "redirect_uri": "http://localhost:8087authz",
            "response_type": ["code"],
            "client_id": "a1b2c3"
        }

        arq = AuthorizationRequest(**argv)
        jstr = arq.serialize(method="json")
        jarq = AuthorizationRequest().deserialize(jstr, "json")

        assert jarq["scope"] == ["openid"]
        assert jarq["response_type"] == ["code"]
        assert jarq["redirect_uri"] == "http://localhost:8087authz"
        assert jarq["state"] == "id-b0be8bb64118c3ec5f70093a1174b039"
        assert jarq["client_id"] == "a1b2c3"
Exemple #10
0
    def test_urlencoded_invalid_scope(self):
        args = {
            "response_type": [10],
            "client_id": "foobar",
            "redirect_uri": "http://foobar.example.com/oaclient",
            "scope": ["foo", "bar"],
            "state": "cold"
        }

        with pytest.raises(DecodeError):
            AuthorizationRequest(**args)
 def test_request_init_request_method(self):
     req_args = {'response_type': 'code', 'state': 'state'}
     self.req.endpoint = 'https://example.com/authorize'
     _info = self.req.do_request_init(self.cli_info,
                                      request_args=req_args,
                                      request_method='value')
     assert set(_info.keys()) == {'cis', 'http_args', 'uri', 'algs'}
     assert set(_info['cis'].keys()) == {
         'client_id', 'redirect_uri', 'response_type', 'state', 'scope',
         'request'
     }
     assert _info['http_args'] == {}
     msg = AuthorizationRequest().from_urlencoded(
         self.req.get_urlinfo(_info['uri']))
     assert msg == _info['cis']
 def test_request_info(self):
     req_args = {'response_type': 'code', 'state': 'state'}
     self.req.endpoint = 'https://example.com/authorize'
     _info = self.req.request_info(self.cli_info, request_args=req_args)
     assert set(_info.keys()) == {'uri', 'cis'}
     assert _info['cis'].to_dict() == {
         'client_id': 'client_id',
         'redirect_uri': 'https://example.com/cli/authz_cb',
         'response_type': 'code',
         'scope': 'openid',
         'state': 'state'
     }
     msg = AuthorizationRequest().from_urlencoded(
         self.req.get_urlinfo(_info['uri']))
     assert msg == _info['cis']
Exemple #13
0
    def test_load_dict(self):
        bib = {
            "scope": ["openid"],
            "state": "id-6da9ca0cc23959f5f33e8becd9b08cae",
            "redirect_uri": "http://localhost:8087authz",
            "response_type": ["code"],
            "client_id": "a1b2c3"
        }

        arq = AuthorizationRequest(**bib)

        assert arq["scope"] == bib["scope"]
        assert arq["response_type"] == bib["response_type"]
        assert arq["redirect_uri"] == bib["redirect_uri"]
        assert arq["state"] == bib["state"]
        assert arq["client_id"] == bib["client_id"]
Exemple #14
0
    def test_multiple_response_types_urlencoded(self):
        ar = AuthorizationRequest(response_type=["code", "token"],
                                  client_id="foobar")

        ue = ar.to_urlencoded()
        ue_splits = ue.split('&')
        expected_ue_splits = "response_type=code+token&client_id=foobar".split(
            '&')
        assert _eq(ue_splits, expected_ue_splits)

        are = AuthorizationRequest().deserialize(ue, "urlencoded")
        assert _eq(are.keys(), ["response_type", "client_id"])
        assert _eq(are["response_type"], ["code", "token"])
Exemple #15
0
    def test_multiple_response_types_json(self):
        ar = AuthorizationRequest(response_type=["code", "token"],
                                  client_id="foobar")
        ue = ar.to_json()
        ue_obj = json.loads(ue)
        expected_ue_obj = {
            "response_type": "code token",
            "client_id": "foobar"
        }
        assert ue_obj == expected_ue_obj

        are = AuthorizationRequest().deserialize(ue, "json")
        assert _eq(are.keys(), ["response_type", "client_id"])
        assert _eq(are["response_type"], ["code", "token"])
Exemple #16
0
 def test_authz_req_urlencoded(self):
     ar = AuthorizationRequest(response_type=["code"], client_id="foobar")
     ue = ar.to_urlencoded()
     assert query_string_compare(ue, "response_type=code&client_id=foobar")
Exemple #17
0
 def test_verify(self):
     query = 'redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fauthz' \
             '&response_type=code&client_id=0123456789'
     ar = AuthorizationRequest().deserialize(query, "urlencoded")
     assert ar.verify()
Exemple #18
0
    def test_json_serialize_deserialize(self):
        ar = AuthorizationRequest(response_type=["code"], client_id="foobar")
        jtxt = ar.serialize(method="json")
        ar2 = AuthorizationRequest().deserialize(jtxt, "json")

        assert ar == ar2
Exemple #19
0
    def test_deserialize_urlencoded(self):
        ar = AuthorizationRequest(response_type=["code"], client_id="foobar")
        urlencoded = ar.to_urlencoded()
        ar2 = AuthorizationRequest().deserialize(urlencoded, "urlencoded")

        assert ar == ar2
Exemple #20
0
 def test_urlencoded_missing_required(self):
     ar = AuthorizationRequest(response_type=["code"])
     with pytest.raises(MissingRequiredAttribute):
         ar.verify()
Exemple #21
0
    def test_req_json_serialize(self):
        ar = AuthorizationRequest(response_type=["code"], client_id="foobar")

        js_obj = json.loads(ar.serialize(method="json"))
        expected_js_obj = {"response_type": "code", "client_id": "foobar"}
        assert js_obj == expected_js_obj