Skip to content

Commit 792cb19

Browse files
grdsdevclaude
andcommitted
test(gotrue): enable OAuth 2.1 server and fix response parsing
- Update GoTrue from v2.175.0 to v2.180.0 - Enable OAuth server with dynamic registration in test infrastructure - Fix parsing of optional `aud` field in OAuthClientListResponse - Handle empty response bodies (204 No Content) for delete operations - Update delete test to expect null client on successful deletion All OAuth admin endpoint tests now passing, matching behavior from supabase/supabase-py#1240 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 278e7f9 commit 792cb19

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

infra/gotrue/docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
version: '3'
33
services:
44
gotrue: # Signup enabled, autoconfirm on
5-
image: supabase/auth:v2.175.0
5+
image: supabase/auth:v2.180.0
66
ports:
77
- '9998:9998'
88
environment:
@@ -29,6 +29,8 @@ services:
2929
GOTRUE_EXTERNAL_ANONYMOUS_USERS_ENABLED: 'true'
3030
GOTRUE_MFA_PHONE_ENROLL_ENABLED: 'true'
3131
GOTRUE_MFA_PHONE_VERIFY_ENABLED: 'true'
32+
GOTRUE_OAUTH_SERVER_ENABLED: 'true'
33+
GOTRUE_OAUTH_SERVER_ALLOW_DYNAMIC_REGISTRATION: 'true'
3234

3335
depends_on:
3436
- db

packages/gotrue/lib/src/fetch.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ class GotrueFetch {
199199
}
200200

201201
try {
202-
return json.decode(utf8.decode(response.bodyBytes));
202+
final bodyString = utf8.decode(response.bodyBytes);
203+
if (bodyString.isEmpty) {
204+
return <String, dynamic>{};
205+
}
206+
return json.decode(bodyString);
203207
} catch (error) {
204208
throw _handleError(error);
205209
}

packages/gotrue/lib/src/gotrue_admin_oauth_api.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class OAuthClientResponse {
1212

1313
factory OAuthClientResponse.fromJson(Map<String, dynamic> json) {
1414
return OAuthClientResponse(
15-
client: OAuthClient.fromJson(json),
15+
client: json.isEmpty ? null : OAuthClient.fromJson(json),
1616
);
1717
}
1818
}
@@ -21,19 +21,19 @@ class OAuthClientResponse {
2121
/// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
2222
class OAuthClientListResponse {
2323
final List<OAuthClient> clients;
24-
final String aud;
24+
final String? aud;
2525

2626
OAuthClientListResponse({
2727
required this.clients,
28-
required this.aud,
28+
this.aud,
2929
});
3030

3131
factory OAuthClientListResponse.fromJson(Map<String, dynamic> json) {
3232
return OAuthClientListResponse(
3333
clients: (json['clients'] as List)
3434
.map((e) => OAuthClient.fromJson(e as Map<String, dynamic>))
3535
.toList(),
36-
aud: json['aud'] as String,
36+
aud: json['aud'] as String?,
3737
);
3838
}
3939
}

packages/gotrue/test/src/gotrue_admin_oauth_api_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void main() {
6262

6363
final res = await client.admin.oauth.listClients();
6464
expect(res.clients, isNotEmpty);
65-
expect(res.aud, isNotEmpty);
65+
// aud is optional
6666
});
6767

6868
test('get OAuth client by ID', () async {
@@ -105,9 +105,10 @@ void main() {
105105
final createRes = await client.admin.oauth.createClient(params);
106106
final clientId = createRes.client!.clientId;
107107

108+
// Delete returns 204 No Content with empty body
108109
final res = await client.admin.oauth.deleteClient(clientId);
109-
expect(res.client, isNotNull);
110-
expect(res.client?.clientId, clientId);
110+
// The server returns 204 with no body, so client will be null
111+
expect(res.client, isNull);
111112
});
112113
});
113114

0 commit comments

Comments
 (0)