Skip to content

Commit 24a160a

Browse files
committed
feat: added oAuth client creditinals
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
1 parent c1aef00 commit 24a160a

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

api/app/settings/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,15 @@
904904
"ROTATE_REFRESH_TOKEN": True,
905905
"PKCE_REQUIRED": True,
906906
"ALLOWED_CODE_CHALLENGE_METHODS": ["S256"],
907-
"SCOPES": {"mcp": "MCP access"},
907+
"SCOPES": {
908+
"mcp": "MCP access",
909+
"scim": "SCIM provisioning access",
910+
},
908911
"DEFAULT_SCOPES": ["mcp"],
909912
"ALLOWED_GRANT_TYPES": [
910913
"authorization_code",
911914
"refresh_token",
915+
"client_credentials",
912916
],
913917
}
914918

api/oauth2_metadata/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def authorization_server_metadata(request: HttpRequest) -> JsonResponse:
2929
frontend_url: str = settings.FLAGSMITH_FRONTEND_URL.rstrip("/")
3030
oauth2_settings: dict[str, Any] = settings.OAUTH2_PROVIDER
3131
scopes: dict[str, str] = oauth2_settings.get("SCOPES", {})
32+
allowed_grant_types: list[str] = oauth2_settings.get(
33+
"ALLOWED_GRANT_TYPES",
34+
["authorization_code", "refresh_token"],
35+
)
3236

3337
metadata = {
3438
"issuer": api_url,
@@ -39,7 +43,7 @@ def authorization_server_metadata(request: HttpRequest) -> JsonResponse:
3943
"introspection_endpoint": f"{api_url}/o/introspect/",
4044
"scopes_supported": list(scopes.keys()),
4145
"response_types_supported": ["code"],
42-
"grant_types_supported": ["authorization_code", "refresh_token"],
46+
"grant_types_supported": allowed_grant_types,
4347
"code_challenge_methods_supported": ["S256"],
4448
"token_endpoint_auth_methods_supported": [
4549
"client_secret_basic",

api/tests/unit/oauth2_metadata/test_views.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,54 @@ def test_metadata_endpoint__post_request__returns_405() -> None:
108108

109109
# Then
110110
assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
111+
112+
113+
def test_metadata_endpoint__grant_types__derived_from_allowed_grant_types_setting(
114+
client: Client,
115+
settings: SettingsWrapper,
116+
) -> None:
117+
# Given
118+
settings.OAUTH2_PROVIDER = {
119+
**settings.OAUTH2_PROVIDER,
120+
"ALLOWED_GRANT_TYPES": ["authorization_code", "client_credentials"],
121+
}
122+
123+
# When
124+
response = client.get(reverse(METADATA_URL))
125+
126+
# Then
127+
data = response.json()
128+
assert data["grant_types_supported"] == ["authorization_code", "client_credentials"]
129+
130+
131+
def test_metadata_endpoint__grant_types__include_client_credentials_by_default(
132+
client: Client,
133+
settings: SettingsWrapper,
134+
) -> None:
135+
# Given
136+
# Use real settings which now include client_credentials
137+
settings.FLAGSMITH_API_URL = "https://api.flagsmith.com"
138+
settings.FLAGSMITH_FRONTEND_URL = "https://app.flagsmith.com"
139+
140+
# When
141+
response = client.get(reverse(METADATA_URL))
142+
143+
# Then
144+
data = response.json()
145+
assert "client_credentials" in data["grant_types_supported"]
146+
147+
148+
def test_metadata_endpoint__scim_scope__present_in_scopes_supported(
149+
client: Client,
150+
settings: SettingsWrapper,
151+
) -> None:
152+
# Given
153+
settings.FLAGSMITH_API_URL = "https://api.flagsmith.com"
154+
settings.FLAGSMITH_FRONTEND_URL = "https://app.flagsmith.com"
155+
156+
# When
157+
response = client.get(reverse(METADATA_URL))
158+
159+
# Then
160+
data = response.json()
161+
assert "scim" in data["scopes_supported"]

0 commit comments

Comments
 (0)