|
15 | 15 | from authlib.oidc.core.grants import OpenIDCode as _OpenIDCode |
16 | 16 | from tests.util import read_file_path |
17 | 17 |
|
| 18 | +from .models import Client |
18 | 19 | from .models import CodeGrantMixin |
19 | 20 | from .models import exists_nonce |
20 | 21 | from .models import save_authorization_code |
@@ -54,7 +55,7 @@ def save_authorization_code(self, code, request): |
54 | 55 | return save_authorization_code(code, request) |
55 | 56 |
|
56 | 57 | class OpenIDCode(_OpenIDCode): |
57 | | - def get_jwt_config(self, grant): |
| 58 | + def get_jwt_config(self, grant, client): |
58 | 59 | key = current_app.config.get("OAUTH2_JWT_KEY") |
59 | 60 | alg = current_app.config.get("OAUTH2_JWT_ALG") |
60 | 61 | iss = current_app.config.get("OAUTH2_JWT_ISS") |
@@ -419,3 +420,64 @@ def test_authorize_token_algs(test_client, server, app, alg, private_key, public |
419 | 420 | claims_options={"iss": {"value": "Authlib"}}, |
420 | 421 | ) |
421 | 422 | claims.validate() |
| 423 | + |
| 424 | + |
| 425 | +def test_deprecated_get_jwt_config_signature(test_client, server, db, user): |
| 426 | + """Using the old get_jwt_config(self, grant) signature should emit a DeprecationWarning.""" |
| 427 | + |
| 428 | + class DeprecatedOpenIDCode(_OpenIDCode): |
| 429 | + def get_jwt_config(self, grant): |
| 430 | + return {"key": "secret", "alg": "HS256", "iss": "Authlib", "exp": 3600} |
| 431 | + |
| 432 | + def exists_nonce(self, nonce, request): |
| 433 | + return exists_nonce(nonce, request) |
| 434 | + |
| 435 | + def generate_user_info(self, user, scopes): |
| 436 | + return user.generate_user_info(scopes) |
| 437 | + |
| 438 | + class AuthorizationCodeGrant(CodeGrantMixin, _AuthorizationCodeGrant): |
| 439 | + def save_authorization_code(self, code, request): |
| 440 | + return save_authorization_code(code, request) |
| 441 | + |
| 442 | + server.register_grant(AuthorizationCodeGrant, [DeprecatedOpenIDCode()]) |
| 443 | + |
| 444 | + client = Client( |
| 445 | + user_id=user.id, |
| 446 | + client_id="deprecated-client", |
| 447 | + client_secret="secret", |
| 448 | + ) |
| 449 | + client.set_client_metadata( |
| 450 | + { |
| 451 | + "redirect_uris": ["https://client.test"], |
| 452 | + "scope": "openid profile", |
| 453 | + "response_types": ["code"], |
| 454 | + "grant_types": ["authorization_code"], |
| 455 | + } |
| 456 | + ) |
| 457 | + db.session.add(client) |
| 458 | + db.session.commit() |
| 459 | + |
| 460 | + rv = test_client.post( |
| 461 | + "/oauth/authorize", |
| 462 | + data={ |
| 463 | + "response_type": "code", |
| 464 | + "client_id": "deprecated-client", |
| 465 | + "state": "bar", |
| 466 | + "scope": "openid profile", |
| 467 | + "redirect_uri": "https://client.test", |
| 468 | + "user_id": "1", |
| 469 | + }, |
| 470 | + ) |
| 471 | + params = dict(url_decode(urlparse.urlparse(rv.location).query)) |
| 472 | + code = params["code"] |
| 473 | + |
| 474 | + with pytest.warns(DeprecationWarning, match="get_jwt_config.*version 1.8"): |
| 475 | + test_client.post( |
| 476 | + "/oauth/token", |
| 477 | + data={ |
| 478 | + "grant_type": "authorization_code", |
| 479 | + "redirect_uri": "https://client.test", |
| 480 | + "code": code, |
| 481 | + }, |
| 482 | + headers=create_basic_header("deprecated-client", "secret"), |
| 483 | + ) |
0 commit comments