|
10 | 10 | import requests
|
11 | 11 |
|
12 | 12 | from oauth2cli.oidc import Client
|
13 |
| -from oauth2cli.authcode import obtain_auth_code |
| 13 | +from oauth2cli.authcode import obtain_auth_code, AuthCodeReceiver |
14 | 14 | from oauth2cli.assertion import JwtSigner
|
15 | 15 | from tests import unittest, Oauth2TestCase
|
16 | 16 | from tests.http_client import MinimalHttpClient, MinimalResponse
|
@@ -153,6 +153,33 @@ def test_auth_code(self):
|
153 | 153 | redirect_uri=redirect_uri)
|
154 | 154 | self.assertLoosely(result, lambda: self.assertIn('access_token', result))
|
155 | 155 |
|
| 156 | + @unittest.skipUnless( |
| 157 | + "authorization_endpoint" in CONFIG.get("openid_configuration", {}), |
| 158 | + "authorization_endpoint missing") |
| 159 | + def test_auth_code_flow(self): |
| 160 | + with AuthCodeReceiver(port=CONFIG.get("listen_port")) as receiver: |
| 161 | + flow = self.client.initiate_auth_code_flow( |
| 162 | + redirect_uri="http://localhost:%d" % receiver.get_port(), |
| 163 | + scope=CONFIG.get("scope"), |
| 164 | + ) |
| 165 | + auth_response = receiver.get_auth_response( |
| 166 | + auth_uri=flow["auth_uri"], |
| 167 | + state=flow["state"], # Optional but recommended |
| 168 | + timeout=120, |
| 169 | + welcome_template="""<html><body> |
| 170 | + authorization_endpoint = {a}, client_id = {i} |
| 171 | + <a href="$auth_uri">Sign In</a> or <a href="$abort_uri">Abort</a> |
| 172 | + </body></html>""".format( |
| 173 | + a=CONFIG["openid_configuration"]["authorization_endpoint"], |
| 174 | + i=CONFIG.get("client_id")), |
| 175 | + ) |
| 176 | + self.assertIsNotNone( |
| 177 | + auth_response.get("code"), "Error: {}, Detail: {}".format( |
| 178 | + auth_response.get("error"), auth_response)) |
| 179 | + result = self.client.obtain_token_by_auth_code_flow(flow, auth_response) |
| 180 | + #TBD: data={"resource": CONFIG.get("resource")}, # MSFT AAD v1 only |
| 181 | + self.assertLoosely(result, lambda: self.assertIn('access_token', result)) |
| 182 | + |
156 | 183 | @unittest.skipUnless(
|
157 | 184 | CONFIG.get("openid_configuration", {}).get("device_authorization_endpoint"),
|
158 | 185 | "device_authorization_endpoint is missing")
|
|
0 commit comments