MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / DCRRequestSerializer

Class DCRRequestSerializer

api/oauth2_metadata/serializers.py:25–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24
25class DCRRequestSerializer(serializers.Serializer[None]):
26 client_name = serializers.CharField(max_length=255, required=True)
27 redirect_uris = serializers.ListField(
28 child=serializers.URLField(),
29 min_length=1,
30 max_length=5,
31 required=True,
32 )
33 grant_types = serializers.ListField(
34 child=serializers.CharField(),
35 required=False,
36 default=["authorization_code", "refresh_token"],
37 )
38 response_types = serializers.ListField(
39 child=serializers.CharField(),
40 required=False,
41 default=["code"],
42 )
43 token_endpoint_auth_method = serializers.CharField(
44 required=False,
45 default="none",
46 )
47
48 def validate_client_name(self, value: str) -> str:
49 if not _CLIENT_NAME_RE.match(value):
50 raise serializers.ValidationError(
51 "Client name may only contain letters, digits, spaces, "
52 "hyphens, underscores, dots, and parentheses."
53 )
54 return value
55
56 def validate_redirect_uris(self, value: list[str]) -> list[str]:
57 errors: list[str] = []
58 for uri in value:
59 try:
60 validate_redirect_uri(uri)
61 except DjangoValidationError as e:
62 errors.append(str(e.message))
63 if errors:
64 raise serializers.ValidationError(errors)
65 return value
66
67 def validate_token_endpoint_auth_method(self, value: str) -> str:
68 if value != "none":
69 raise serializers.ValidationError(
70 "Only public clients are supported; "
71 "token_endpoint_auth_method must be 'none'."
72 )
73 return value
74
75 def validate_grant_types(self, value: list[str]) -> list[str]:
76 allowed = {"authorization_code", "refresh_token"}
77 invalid = set(value) - allowed
78 if invalid:
79 raise serializers.ValidationError(
80 f"Unsupported grant types: {', '.join(sorted(invalid))}"
81 )
82 return value

Callers 1

postMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…