Skip to content

Commit a74c41f

Browse files
authored
Merge pull request #267 from relaystr/blossom-missing-authorization
Blossom missing authorization
2 parents 420c1d5 + 3f54036 commit a74c41f

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

packages/ndk/lib/data_layer/repositories/blossom/blossom_impl.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,15 @@ class BlossomRepositoryImpl implements BlossomRepository {
418418
if (until != null) 'until': '${until.millisecondsSinceEpoch ~/ 1000}',
419419
};
420420

421+
final headers = <String, String>{};
422+
if (authorization != null) {
423+
headers['Authorization'] = "Nostr ${authorization.toBase64()}";
424+
}
425+
421426
final response = await client.get(
422427
url: Uri.parse('$url/list/$pubkey')
423428
.replace(queryParameters: queryParams),
429+
headers: headers,
424430
);
425431

426432
if (response.statusCode == 200) {

packages/ndk/test/mocks/mock_blossom_server.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ class MockBlossomServer {
9090

9191
// GET /list/<pubkey> - List Blobs
9292
router.get('/list/<pubkey>', (Request request, String pubkey) {
93+
final authHeader = request.headers['authorization'];
94+
95+
if (authHeader == null) {
96+
return Response.forbidden('Missing authorization');
97+
}
98+
99+
try {
100+
final authEvent =
101+
json.decode(utf8.decode(base64Decode(authHeader.split(' ')[1])));
102+
if (!_verifyAuthEvent(authEvent, 'list')) {
103+
return Response.forbidden('Invalid authorization event');
104+
}
105+
} catch (e) {
106+
return Response.forbidden('Invalid authorization format');
107+
}
108+
93109
final since = int.tryParse(request.url.queryParameters['since'] ?? '');
94110
final until = int.tryParse(request.url.queryParameters['until'] ?? '');
95111

packages/ndk/test/usecases/files/blossom_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,19 @@ void main() {
463463
expect(reportRsp, equals(200));
464464
});
465465
});
466+
467+
test('Get blobs with NDK', () async {
468+
final ndk = Ndk.defaultConfig();
469+
470+
final keyPair = Bip340.generatePrivateKey();
471+
ndk.accounts.loginPrivateKey(
472+
pubkey: keyPair.publicKey,
473+
privkey: keyPair.privateKey!,
474+
);
475+
476+
await ndk.blossom.listBlobs(
477+
pubkey: ndk.accounts.getPublicKey()!,
478+
serverUrls: ["http://localhost:3000"],
479+
);
480+
});
466481
}

0 commit comments

Comments
 (0)