Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344import { test } from 'node:test';import assert from 'node:assert/strict';import { clientMetadata, scopes } from '../src/index.ts';
const SCOPES = 'atproto repo:dev.nibling.project repo:dev.nibling.feed.like repo:dev.nibling.feed.comment ' + 'repo:dev.nibling.graph.follow repo:dev.nibling.actor.profile repo:dev.nibling.actor.settings blob:*/* rpc:org.tangled.git.receivePack?aud=* rpc:dev.nibling.ssh.attach?aud=* rpc:dev.nibling.relay.join?aud=*';
test('scopes is the D19 scope string', () => { assert.equal(scopes, SCOPES);});
test('clientMetadata for a hosted origin points at its client-metadata.json', () => { assert.deepEqual(clientMetadata({ origin: 'https://nibling.run', name: 'nibling' }), { client_id: 'https://nibling.run/oauth/client-metadata.json', client_name: 'nibling', client_uri: 'https://nibling.run', redirect_uris: ['https://nibling.run/oauth/callback'], scope: SCOPES, grant_types: ['authorization_code', 'refresh_token'], response_types: ['code'], token_endpoint_auth_method: 'none', application_type: 'web', dpop_bound_access_tokens: true, });});
test('clientMetadata for 127.0.0.1 uses the http://localhost loopback client ID', () => { const metadata = clientMetadata({ origin: 'http://127.0.0.1:5173', name: 'nibling' }); const id = new URL(metadata.client_id); assert.equal(id.origin, 'http://localhost'); assert.equal(id.searchParams.get('redirect_uri'), 'http://127.0.0.1:5173/oauth/callback'); assert.equal(id.searchParams.get('scope'), SCOPES); assert.deepEqual(metadata.redirect_uris, ['http://127.0.0.1:5173/oauth/callback']); assert.equal(metadata.client_name, undefined);});
test('clientMetadata refuses http://localhost, whose storage the 127.0.0.1 callback cannot see', () => { assert.throws( () => clientMetadata({ origin: 'http://localhost:5173', name: 'nibling' }), (err) => err instanceof Error && 'code' in err && err.code === 'ERR_NIB_AUTH_LOOPBACK', );});