Skip to content

Commit 8037c2d

Browse files
committed
login: Mark WebAuthPayload.userId as required, relying on server 5+, FL 108+.
See "Feature level 108" from Zulip API changelog: https://zulip.com/api/changelog Signed-off-by: Zixuan James Li <[email protected]>
1 parent efe7ca9 commit 8037c2d

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

lib/api/model/web_auth.dart

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:flutter/foundation.dart';
77
class WebAuthPayload {
88
final Uri realm;
99
final String email;
10-
final int? userId; // TODO(server-5) new in FL 108
10+
final int userId;
1111
final String otpEncryptedApiKey;
1212

1313
WebAuthPayload._({
@@ -25,21 +25,16 @@ class WebAuthPayload {
2525
queryParameters: {
2626
'realm': String realmStr,
2727
'email': String email,
28-
// 'user_id' handled below
28+
'user_id': String userIdStr,
2929
'otp_encrypted_api_key': String otpEncryptedApiKey,
3030
},
3131
)
3232
) {
3333
final Uri? realm = Uri.tryParse(realmStr);
3434
if (realm == null) throw const FormatException();
3535

36-
// TODO(server-5) require in queryParameters (new in FL 108)
37-
final userIdStr = url.queryParameters['user_id'];
38-
int? userId;
39-
if (userIdStr != null) {
40-
userId = int.tryParse(userIdStr, radix: 10);
41-
if (userId == null) throw const FormatException();
42-
}
36+
final userId = int.tryParse(userIdStr, radix: 10);
37+
if (userId == null) throw const FormatException();
4338

4439
if (!RegExp(r'^[0-9a-fA-F]{64}$').hasMatch(otpEncryptedApiKey)) {
4540
throw const FormatException();

lib/widgets/login.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ class _LoginPageState extends State<LoginPage> {
293293
if (payload.realm.origin != widget.serverSettings.realmUrl.origin) throw Error();
294294
final apiKey = payload.decodeApiKey(_otp!);
295295
await _tryInsertAccountAndNavigate(
296-
// TODO(server-5): Rely on userId from payload.
297-
userId: payload.userId ?? await _getUserId(payload.email, apiKey),
296+
userId: payload.userId,
298297
email: payload.email,
299298
apiKey: apiKey,
300299
);

test/api/model/web_auth_test.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ void main() {
2323
check(payload.decodeApiKey(otp)).equals(eg.selfAccount.apiKey);
2424
});
2525

26-
// TODO(server-5) remove
27-
test('legacy: no userId', () {
28-
final queryParams = {...wellFormed.queryParameters}..remove('user_id');
29-
final payload = WebAuthPayload.parse(
30-
wellFormed.replace(queryParameters: queryParams));
31-
check(payload)
32-
..otpEncryptedApiKey.equals(encryptedApiKey)
33-
..email.equals('self@example')
34-
..userId.isNull()
35-
..realm.equals(Uri.parse('https://chat.example/'));
36-
check(payload.decodeApiKey(otp)).equals(eg.selfAccount.apiKey);
37-
});
38-
3926
test('parse fails when an expected field is missing', () {
4027
final queryParams = {...wellFormed.queryParameters}..remove('email');
4128
final input = wellFormed.replace(queryParameters: queryParams);
@@ -93,6 +80,6 @@ void main() {
9380
extension WebAuthPayloadChecks on Subject<WebAuthPayload> {
9481
Subject<String> get otpEncryptedApiKey => has((x) => x.otpEncryptedApiKey, 'otpEncryptedApiKey');
9582
Subject<String> get email => has((x) => x.email, 'email');
96-
Subject<int?> get userId => has((x) => x.userId, 'userId');
83+
Subject<int> get userId => has((x) => x.userId, 'userId');
9784
Subject<Uri> get realm => has((x) => x.realm, 'realm');
9885
}

0 commit comments

Comments
 (0)