|
19 | 19 | key_defs=KEYSPEC, issuer_id='client_id')
|
20 | 20 |
|
21 | 21 |
|
22 |
| -class TestDPoP: |
| 22 | +class TestDPoPWithoutUserinfo: |
23 | 23 | @pytest.fixture(autouse=True)
|
24 | 24 | def create_client(self):
|
25 | 25 | config = {
|
@@ -67,3 +67,92 @@ def test_add_header(self):
|
67 | 67 | assert _header["alg"] == "ES256"
|
68 | 68 | assert _header["jwk"]["kty"] == "EC"
|
69 | 69 | assert _header["jwk"]["crv"] == "P-256"
|
| 70 | + |
| 71 | + |
| 72 | +class TestDPoPWithUserinfo: |
| 73 | + @pytest.fixture(autouse=True) |
| 74 | + def create_client(self): |
| 75 | + config = { |
| 76 | + 'client_id': 'client_id', |
| 77 | + 'client_secret': 'a longesh password', |
| 78 | + 'redirect_uris': ['https://example.com/cli/authz_cb'], |
| 79 | + 'behaviour': {'response_types': ['code']}, |
| 80 | + 'add_ons': { |
| 81 | + "dpop": { |
| 82 | + "function": "oidcrp.oauth2.add_on.dpop.add_support", |
| 83 | + "kwargs": { |
| 84 | + "signing_algorithms": ["ES256", "ES512"] |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + services = { |
| 91 | + "discovery": { |
| 92 | + 'class': 'oidcrp.oauth2.provider_info_discovery.ProviderInfoDiscovery' |
| 93 | + }, |
| 94 | + 'authorization': { |
| 95 | + 'class': 'oidcrp.oauth2.authorization.Authorization' |
| 96 | + }, |
| 97 | + 'access_token': { |
| 98 | + 'class': 'oidcrp.oauth2.access_token.AccessToken' |
| 99 | + }, |
| 100 | + 'refresh_access_token': { |
| 101 | + 'class': 'oidcrp.oauth2.refresh_access_token.RefreshAccessToken' |
| 102 | + }, |
| 103 | + 'userinfo': { |
| 104 | + 'class': 'oidcrp.oidc.userinfo.UserInfo' |
| 105 | + } |
| 106 | + } |
| 107 | + self.client = Client(keyjar=CLI_KEY, config=config, services=services) |
| 108 | + |
| 109 | + self.client.client_get("service_context").provider_info = { |
| 110 | + "authorization_endpoint": "https://example.com/auth", |
| 111 | + "token_endpoint": "https://example.com/token", |
| 112 | + "dpop_signing_alg_values_supported": ["RS256", "ES256"], |
| 113 | + "userinfo_endpoint": "https://example.com/user", |
| 114 | + } |
| 115 | + |
| 116 | + def test_add_header_token(self): |
| 117 | + token_serv = self.client.client_get("service", "accesstoken") |
| 118 | + req_args = { |
| 119 | + "grant_type": "authorization_code", |
| 120 | + "code": "SplxlOBeZQQYbYS6WxSbIA", |
| 121 | + "redirect_uri": "https://client/example.com/cb" |
| 122 | + } |
| 123 | + headers = token_serv.get_headers(request=req_args, http_method="POST") |
| 124 | + assert headers |
| 125 | + assert "dpop" in headers |
| 126 | + |
| 127 | + # Now for the content of the DPoP proof |
| 128 | + _jws = factory(headers["dpop"]) |
| 129 | + _payload = _jws.jwt.payload() |
| 130 | + assert _payload["htu"] == "https://example.com/token" |
| 131 | + assert _payload["htm"] == "POST" |
| 132 | + _header = _jws.jwt.headers |
| 133 | + assert "jwk" in _header |
| 134 | + assert _header["typ"] == "dpop+jwt" |
| 135 | + assert _header["alg"] == "ES256" |
| 136 | + assert _header["jwk"]["kty"] == "EC" |
| 137 | + assert _header["jwk"]["crv"] == "P-256" |
| 138 | + |
| 139 | + def test_add_header_userinfo(self): |
| 140 | + userinfo_serv = self.client.client_get("service", "userinfo") |
| 141 | + req_args = {} |
| 142 | + access_token = 'access.token.sign' |
| 143 | + headers = userinfo_serv.get_headers(request=req_args, http_method="GET", |
| 144 | + access_token=access_token) |
| 145 | + assert headers |
| 146 | + assert "dpop" in headers |
| 147 | + |
| 148 | + # Now for the content of the DPoP proof |
| 149 | + _jws = factory(headers["dpop"]) |
| 150 | + _payload = _jws.jwt.payload() |
| 151 | + assert _payload["htu"] == "https://example.com/user" |
| 152 | + assert _payload["htm"] == "GET" |
| 153 | + _header = _jws.jwt.headers |
| 154 | + assert "jwk" in _header |
| 155 | + assert _header["typ"] == "dpop+jwt" |
| 156 | + assert _header["alg"] == "ES256" |
| 157 | + assert _header["jwk"]["kty"] == "EC" |
| 158 | + assert _header["jwk"]["crv"] == "P-256" |
0 commit comments