mirror of
https://github.com/block/buzz.git
synced 2026-11-04 16:31:38 +00:00
fix(mobile): let the issuer choose relay assertion lifetime
Mobile rejected any NIP-FI relay assertion expiring more than 300s out, so once the issuer moves to longer lifetimes, org sign-in fails on every fetch and the Block relay can't connect. Keep the expired check and drop the cap, matching desktop (block/buzz-app#2171). The token cache already refreshes from expires_at. Co-authored-by: claude00 <fb8b76a01257932b8ca35060862c29bd09b2137638573731c2d5074fc02c5385@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Bradley Axen <baxen@squareup.com>
This commit is contained in:
@@ -223,7 +223,7 @@ class HostedRelayAuth extends ChangeNotifier {
|
|||||||
throw AccountFailure.invalidResponse;
|
throw AccountFailure.invalidResponse;
|
||||||
}
|
}
|
||||||
final now = _now().millisecondsSinceEpoch ~/ 1000;
|
final now = _now().millisecondsSinceEpoch ~/ 1000;
|
||||||
if (expiry <= now || expiry > now + 300) {
|
if (expiry <= now) {
|
||||||
throw AccountFailure.invalidResponse;
|
throw AccountFailure.invalidResponse;
|
||||||
}
|
}
|
||||||
final expires = DateTime.fromMillisecondsSinceEpoch(
|
final expires = DateTime.fromMillisecondsSinceEpoch(
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ void main() {
|
|||||||
group('organization relay assertions', () {
|
group('organization relay assertions', () {
|
||||||
late List<http.Request> requests;
|
late List<http.Request> requests;
|
||||||
late Object? boundIdentity;
|
late Object? boundIdentity;
|
||||||
|
late int assertionLifetime;
|
||||||
|
|
||||||
BuilderlabAccountClient organizationClient() => BuilderlabAccountClient(
|
BuilderlabAccountClient organizationClient() => BuilderlabAccountClient(
|
||||||
accountOrigin: organization,
|
accountOrigin: organization,
|
||||||
@@ -110,7 +111,9 @@ void main() {
|
|||||||
jsonEncode({
|
jsonEncode({
|
||||||
'assertion': 'org-token',
|
'assertion': 'org-token',
|
||||||
'nostr_pubkey': keys.public,
|
'nostr_pubkey': keys.public,
|
||||||
'expires_at': DateTime.now().millisecondsSinceEpoch ~/ 1000 + 120,
|
'expires_at':
|
||||||
|
DateTime.now().millisecondsSinceEpoch ~/ 1000 +
|
||||||
|
assertionLifetime,
|
||||||
}),
|
}),
|
||||||
200,
|
200,
|
||||||
),
|
),
|
||||||
@@ -145,6 +148,7 @@ void main() {
|
|||||||
setUp(() {
|
setUp(() {
|
||||||
requests = [];
|
requests = [];
|
||||||
boundIdentity = null;
|
boundIdentity = null;
|
||||||
|
assertionLifetime = 120;
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
@@ -173,6 +177,29 @@ void main() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test('the issuer chooses the lifetime of an unexpired assertion', () async {
|
||||||
|
await saveSession();
|
||||||
|
for (final (lifetime, accepted) in [
|
||||||
|
(300, true),
|
||||||
|
(86400, true),
|
||||||
|
(0, false),
|
||||||
|
(-60, false),
|
||||||
|
]) {
|
||||||
|
assertionLifetime = lifetime;
|
||||||
|
final auth = relayAuth(organizationClient());
|
||||||
|
if (accepted) {
|
||||||
|
expect(await auth.headers(relay), {
|
||||||
|
'Nostr-Federated-Identity': 'Bearer org-token',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await expectLater(
|
||||||
|
auth.headers(relay),
|
||||||
|
throwsA(AccountFailure.invalidResponse),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('a key bound to the same member is accepted', () async {
|
test('a key bound to the same member is accepted', () async {
|
||||||
await saveSession();
|
await saveSession();
|
||||||
boundIdentity = {'pubkey_hex': keys.public};
|
boundIdentity = {'pubkey_hex': keys.public};
|
||||||
|
|||||||
Reference in New Issue
Block a user