Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/supabase_auth/lib/src/auth_admin_oauth_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class OAuthClientListResponse {
.map((e) => OAuthClient.fromJson(e as Map<String, dynamic>))
.toList(),
audience: json['aud'] as String?,
nextPage: json['nextPage'] as int?,
lastPage: json['lastPage'] as int?,
total: json['total'] as int? ?? 0,
nextPage: (json['nextPage'] as num?)?.toInt(),
lastPage: (json['lastPage'] as num?)?.toInt(),
total: (json['total'] as num?)?.toInt() ?? 0,
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/supabase_auth/lib/src/types/jwt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class JwtPayload {
issuer: json['iss'] as String?,
subject: json['sub'] as String?,
audience: json['aud'],
expiresAt: json['exp'] as int?,
notBefore: json['nbf'] as int?,
issuedAt: json['iat'] as int?,
expiresAt: (json['exp'] as num?)?.toInt(),
notBefore: (json['nbf'] as num?)?.toInt(),
issuedAt: (json['iat'] as num?)?.toInt(),
jwtId: json['jti'] as String?,
claims: Map<String, dynamic>.of(json),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/supabase_auth/lib/src/types/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Session {
}
return Session(
accessToken: json['access_token'] as String,
expiresIn: json['expires_in'] as int?,
expiresIn: (json['expires_in'] as num?)?.toInt(),
refreshToken: json['refresh_token'] as String?,
tokenType: json['token_type'] as String,
providerToken: json['provider_token'] as String?,
Expand Down
16 changes: 16 additions & 0 deletions packages/supabase_auth/test/src/helper_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:supabase_auth/src/helper.dart';
import 'package:supabase_auth/src/types/jwt.dart';
import 'package:test/test.dart';

void main() {
Expand Down Expand Up @@ -363,4 +364,19 @@ void main() {
});
});
});

group('JwtPayload', () {
test('fromJson accepts double exp, nbf, and iat', () {
final payload = JwtPayload.fromJson({
'sub': '1234567890',
'exp': 1700000000.0,
'nbf': 1600000000.0,
'iat': 1650000000.0,
});

expect(payload.expiresAt, equals(1700000000));
expect(payload.notBefore, equals(1600000000));
expect(payload.issuedAt, equals(1650000000));
});
});
}
20 changes: 20 additions & 0 deletions packages/supabase_auth/test/src/types/session_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ void main() {
);
expect(session.user.id, equals('123'));
});

test('accepts a double expires_in, as sent by a BroadcastChannel', () {
final json = {
'access_token': 'test-access-token',
'expires_in': 3600.0,
'token_type': 'bearer',
'user': {
'id': '123',
'app_metadata': <String, dynamic>{},
'user_metadata': <String, dynamic>{},
'aud': 'authenticated',
'created_at': '2023-01-01T00:00:00Z',
},
};

final session = Session.fromJson(json);

expect(session, isNotNull);
expect(session!.expiresIn, equals(3600));
});
});

group('toJson', () {
Expand Down
Loading