1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
|
from flask import json
from authlib.jose import jwt
from authlib.oauth2.rfc7591 import ClientMetadataClaims as OAuth2ClientMetadataClaims
from authlib.oauth2.rfc7591 import (
ClientRegistrationEndpoint as _ClientRegistrationEndpoint,
)
from authlib.oidc.registration import ClientMetadataClaims as OIDCClientMetadataClaims
from tests.util import read_file_path
from .models import Client
from .models import User
from .models import db
from .oauth2_server import TestCase
from .oauth2_server import create_authorization_server
class ClientRegistrationEndpoint(_ClientRegistrationEndpoint):
software_statement_alg_values_supported = ["RS256"]
def authenticate_token(self, request):
auth_header = request.headers.get("Authorization")
if auth_header:
request.user_id = 1
return auth_header
def resolve_public_key(self, request):
return read_file_path("rsa_public.pem")
def save_client(self, client_info, client_metadata, request):
client = Client(user_id=request.user_id, **client_info)
client.set_client_metadata(client_metadata)
db.session.add(client)
db.session.commit()
return client
class OAuthClientRegistrationTest(TestCase):
def prepare_data(self, endpoint_cls=None, metadata=None):
app = self.app
server = create_authorization_server(app)
if endpoint_cls:
server.register_endpoint(endpoint_cls)
else:
class MyClientRegistration(ClientRegistrationEndpoint):
def get_server_metadata(self):
return metadata
server.register_endpoint(MyClientRegistration)
@app.route("/create_client", methods=["POST"])
def create_client():
return server.create_endpoint_response("client_registration")
user = User(username="foo")
db.session.add(user)
db.session.commit()
def test_access_denied(self):
self.prepare_data()
rv = self.client.post("/create_client", json={})
resp = json.loads(rv.data)
assert resp["error"] == "access_denied"
def test_invalid_request(self):
self.prepare_data()
headers = {"Authorization": "bearer abc"}
rv = self.client.post("/create_client", json={}, headers=headers)
resp = json.loads(rv.data)
assert resp["error"] == "invalid_request"
def test_create_client(self):
self.prepare_data()
headers = {"Authorization": "bearer abc"}
body = {"client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
def test_software_statement(self):
payload = {"software_id": "uuid-123", "client_name": "Authlib"}
s = jwt.encode({"alg": "RS256"}, payload, read_file_path("rsa_private.pem"))
body = {
"software_statement": s.decode("utf-8"),
}
self.prepare_data()
headers = {"Authorization": "bearer abc"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
def test_no_public_key(self):
class ClientRegistrationEndpoint2(ClientRegistrationEndpoint):
def get_server_metadata(self):
return None
def resolve_public_key(self, request):
return None
payload = {"software_id": "uuid-123", "client_name": "Authlib"}
s = jwt.encode({"alg": "RS256"}, payload, read_file_path("rsa_private.pem"))
body = {
"software_statement": s.decode("utf-8"),
}
self.prepare_data(ClientRegistrationEndpoint2)
headers = {"Authorization": "bearer abc"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert resp["error"] in "unapproved_software_statement"
def test_scopes_supported(self):
metadata = {"scopes_supported": ["profile", "email"]}
self.prepare_data(metadata=metadata)
headers = {"Authorization": "bearer abc"}
body = {"scope": "profile email", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
body = {"scope": "profile email address", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_response_types_supported(self):
metadata = {"response_types_supported": ["code", "code id_token"]}
self.prepare_data(metadata=metadata)
headers = {"Authorization": "bearer abc"}
body = {"response_types": ["code"], "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
# The items order should not matter
# Extension response types MAY contain a space-delimited (%x20) list of
# values, where the order of values does not matter (e.g., response
# type "a b" is the same as "b a").
headers = {"Authorization": "bearer abc"}
body = {"response_types": ["id_token code"], "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
self.assertIn("client_id", resp)
self.assertEqual(resp["client_name"], "Authlib")
# https://www.rfc-editor.org/rfc/rfc7591.html#section-2
# If omitted, the default is that the client will use only the "code"
# response type.
body = {"client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
body = {"response_types": ["code", "token"], "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_grant_types_supported(self):
metadata = {"grant_types_supported": ["authorization_code", "password"]}
self.prepare_data(metadata=metadata)
headers = {"Authorization": "bearer abc"}
body = {"grant_types": ["password"], "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
# https://www.rfc-editor.org/rfc/rfc7591.html#section-2
# If omitted, the default behavior is that the client will use only
# the "authorization_code" Grant Type.
body = {"client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
body = {"grant_types": ["client_credentials"], "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_token_endpoint_auth_methods_supported(self):
metadata = {"token_endpoint_auth_methods_supported": ["client_secret_basic"]}
self.prepare_data(metadata=metadata)
headers = {"Authorization": "bearer abc"}
body = {
"token_endpoint_auth_method": "client_secret_basic",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
body = {"token_endpoint_auth_method": "none", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
class OIDCClientRegistrationTest(TestCase):
def prepare_data(self, metadata=None):
self.headers = {"Authorization": "bearer abc"}
app = self.app
server = create_authorization_server(app)
class MyClientRegistration(ClientRegistrationEndpoint):
def get_server_metadata(self):
return metadata
server.register_endpoint(
MyClientRegistration(
claims_classes=[OAuth2ClientMetadataClaims, OIDCClientMetadataClaims]
)
)
@app.route("/create_client", methods=["POST"])
def create_client():
return server.create_endpoint_response("client_registration")
user = User(username="foo")
db.session.add(user)
db.session.commit()
def test_application_type(self):
self.prepare_data()
# Nominal case
body = {
"application_type": "web",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["application_type"] == "web"
# Default case
# The default, if omitted, is that any algorithm supported by the OP and the RP MAY be used.
body = {
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["application_type"] == "web"
# Error case
body = {
"application_type": "invalid",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_token_endpoint_auth_signing_alg_supported(self):
metadata = {
"token_endpoint_auth_signing_alg_values_supported": ["RS256", "ES256"]
}
self.prepare_data(metadata)
# Nominal case
body = {
"token_endpoint_auth_signing_alg": "ES256",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["token_endpoint_auth_signing_alg"] == "ES256"
# Default case
# The default, if omitted, is that any algorithm supported by the OP and the RP MAY be used.
body = {
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
# Error case
body = {
"token_endpoint_auth_signing_alg": "RS512",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_subject_types_supported(self):
metadata = {"subject_types_supported": ["public", "pairwise"]}
self.prepare_data(metadata)
# Nominal case
body = {"subject_type": "public", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["subject_type"] == "public"
# Error case
body = {"subject_type": "invalid", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_id_token_signing_alg_values_supported(self):
metadata = {"id_token_signing_alg_values_supported": ["RS256", "ES256"]}
self.prepare_data(metadata)
# Default
# The default, if omitted, is RS256.
body = {"client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["id_token_signed_response_alg"] == "RS256"
# Nominal case
body = {"id_token_signed_response_alg": "ES256", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["id_token_signed_response_alg"] == "ES256"
# Error case
body = {"id_token_signed_response_alg": "RS512", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_id_token_signing_alg_values_none(self):
# The value none MUST NOT be used as the ID Token alg value unless the Client uses
# only Response Types that return no ID Token from the Authorization Endpoint
# (such as when only using the Authorization Code Flow).
metadata = {"id_token_signing_alg_values_supported": ["none", "RS256", "ES256"]}
self.prepare_data(metadata)
# Nominal case
body = {
"id_token_signed_response_alg": "none",
"client_name": "Authlib",
"response_type": "code",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
self.assertIn("client_id", resp)
self.assertEqual(resp["client_name"], "Authlib")
self.assertEqual(resp["id_token_signed_response_alg"], "none")
# Error case
body = {
"id_token_signed_response_alg": "none",
"client_name": "Authlib",
"response_type": "id_token",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
self.assertIn(resp["error"], "invalid_client_metadata")
def test_id_token_encryption_alg_values_supported(self):
metadata = {"id_token_encryption_alg_values_supported": ["RS256", "ES256"]}
self.prepare_data(metadata)
# Default case
body = {"client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert "id_token_encrypted_response_enc" not in resp
# If id_token_encrypted_response_alg is specified, the default
# id_token_encrypted_response_enc value is A128CBC-HS256.
body = {"id_token_encrypted_response_alg": "RS256", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["id_token_encrypted_response_enc"] == "A128CBC-HS256"
# Nominal case
body = {"id_token_encrypted_response_alg": "ES256", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["id_token_encrypted_response_alg"] == "ES256"
# Error case
body = {"id_token_encrypted_response_alg": "RS512", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_id_token_encryption_enc_values_supported(self):
metadata = {
"id_token_encryption_enc_values_supported": ["A128CBC-HS256", "A256GCM"]
}
self.prepare_data(metadata)
# Nominal case
body = {
"id_token_encrypted_response_alg": "RS256",
"id_token_encrypted_response_enc": "A256GCM",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["id_token_encrypted_response_alg"] == "RS256"
assert resp["id_token_encrypted_response_enc"] == "A256GCM"
# Error case: missing id_token_encrypted_response_alg
body = {"id_token_encrypted_response_enc": "A256GCM", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
# Error case: alg not in server metadata
body = {"id_token_encrypted_response_enc": "A128GCM", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_userinfo_signing_alg_values_supported(self):
metadata = {"userinfo_signing_alg_values_supported": ["RS256", "ES256"]}
self.prepare_data(metadata)
# Nominal case
body = {"userinfo_signed_response_alg": "ES256", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["userinfo_signed_response_alg"] == "ES256"
# Error case
body = {"userinfo_signed_response_alg": "RS512", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_userinfo_encryption_alg_values_supported(self):
metadata = {"userinfo_encryption_alg_values_supported": ["RS256", "ES256"]}
self.prepare_data(metadata)
# Nominal case
body = {"userinfo_encrypted_response_alg": "ES256", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["userinfo_encrypted_response_alg"] == "ES256"
# Error case
body = {"userinfo_encrypted_response_alg": "RS512", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_userinfo_encryption_enc_values_supported(self):
metadata = {
"userinfo_encryption_enc_values_supported": ["A128CBC-HS256", "A256GCM"]
}
self.prepare_data(metadata)
# Default case
body = {"client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert "userinfo_encrypted_response_enc" not in resp
# If userinfo_encrypted_response_alg is specified, the default
# userinfo_encrypted_response_enc value is A128CBC-HS256.
body = {"userinfo_encrypted_response_alg": "RS256", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["userinfo_encrypted_response_enc"] == "A128CBC-HS256"
# Nominal case
body = {
"userinfo_encrypted_response_alg": "RS256",
"userinfo_encrypted_response_enc": "A256GCM",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["userinfo_encrypted_response_alg"] == "RS256"
assert resp["userinfo_encrypted_response_enc"] == "A256GCM"
# Error case: no userinfo_encrypted_response_alg
body = {"userinfo_encrypted_response_enc": "A256GCM", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
# Error case: alg not in server metadata
body = {"userinfo_encrypted_response_enc": "A128GCM", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_acr_values_supported(self):
metadata = {
"acr_values_supported": [
"urn:mace:incommon:iap:silver",
"urn:mace:incommon:iap:bronze",
],
}
self.prepare_data(metadata)
# Nominal case
body = {
"default_acr_values": ["urn:mace:incommon:iap:silver"],
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["default_acr_values"] == ["urn:mace:incommon:iap:silver"]
# Error case
body = {
"default_acr_values": [
"urn:mace:incommon:iap:silver",
"urn:mace:incommon:iap:gold",
],
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_request_object_signing_alg_values_supported(self):
metadata = {"request_object_signing_alg_values_supported": ["RS256", "ES256"]}
self.prepare_data(metadata)
# Nominal case
body = {"request_object_signing_alg": "ES256", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["request_object_signing_alg"] == "ES256"
# Error case
body = {"request_object_signing_alg": "RS512", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_request_object_encryption_alg_values_supported(self):
metadata = {
"request_object_encryption_alg_values_supported": ["RS256", "ES256"]
}
self.prepare_data(metadata)
# Nominal case
body = {
"request_object_encryption_alg": "ES256",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["request_object_encryption_alg"] == "ES256"
# Error case
body = {
"request_object_encryption_alg": "RS512",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_request_object_encryption_enc_values_supported(self):
metadata = {
"request_object_encryption_enc_values_supported": [
"A128CBC-HS256",
"A256GCM",
]
}
self.prepare_data(metadata)
# Default case
body = {"client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert "request_object_encryption_enc" not in resp
# If request_object_encryption_alg is specified, the default
# request_object_encryption_enc value is A128CBC-HS256.
body = {"request_object_encryption_alg": "RS256", "client_name": "Authlib"}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["request_object_encryption_enc"] == "A128CBC-HS256"
# Nominal case
body = {
"request_object_encryption_alg": "RS256",
"request_object_encryption_enc": "A256GCM",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["request_object_encryption_alg"] == "RS256"
assert resp["request_object_encryption_enc"] == "A256GCM"
# Error case: missing request_object_encryption_alg
body = {
"request_object_encryption_enc": "A256GCM",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
# Error case: alg not in server metadata
body = {
"request_object_encryption_enc": "A128GCM",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_require_auth_time(self):
self.prepare_data()
# Default case
body = {
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["require_auth_time"] is False
# Nominal case
body = {
"require_auth_time": True,
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["require_auth_time"] is True
# Error case
body = {
"require_auth_time": "invalid",
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
def test_redirect_uri(self):
"""RFC6749 indicate that fragments are forbidden in redirect_uri.
The redirection endpoint URI MUST be an absolute URI as defined by
[RFC3986] Section 4.3. [...] The endpoint URI MUST NOT include a
fragment component.
https://www.rfc-editor.org/rfc/rfc6749#section-3.1.2
"""
self.prepare_data()
# Nominal case
body = {
"redirect_uris": ["https://client.test"],
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert "client_id" in resp
assert resp["client_name"] == "Authlib"
assert resp["redirect_uris"] == ["https://client.test"]
# Error case
body = {
"redirect_uris": ["https://client.test#fragment"],
"client_name": "Authlib",
}
rv = self.client.post("/create_client", json=body, headers=self.headers)
resp = json.loads(rv.data)
assert resp["error"] in "invalid_client_metadata"
|