Lanyards is a dedicated profile for researchers, built on the AT Protocol.
1/**
2 * App Password Authentication
3 *
4 * Simpler authentication method using Bluesky app passwords.
5 * Recommended for local development and testing.
6 *
7 * To create an app password:
8 * 1. Go to https://bsky.app/settings/app-passwords
9 * 2. Create a new app password
10 * 3. Add it to your .env file
11 */
12
13import { AtpAgent } from '@atproto/api';
14
15export async function loginWithAppPassword(
16 identifier: string,
17 password: string,
18 pdsUrl?: string
19): Promise<{
20 did: string;
21 handle: string;
22 accessJwt: string;
23 refreshJwt: string;
24}> {
25 const serviceUrl = pdsUrl || process.env.PDS_URL || 'https://bsky.social';
26
27 const agent = new AtpAgent({
28 service: serviceUrl,
29 });
30
31 const response = await agent.login({
32 identifier,
33 password,
34 });
35
36 if (!response.success) {
37 throw new Error('Login failed');
38 }
39
40 return {
41 did: response.data.did,
42 handle: response.data.handle,
43 accessJwt: response.data.accessJwt,
44 refreshJwt: response.data.refreshJwt,
45 };
46}
47
48export async function getConfiguredCredentials(): Promise<{
49 handle: string;
50 password: string;
51} | null> {
52 const handle = process.env.BLUESKY_HANDLE;
53 const password = process.env.BLUESKY_APP_PASSWORD;
54
55 if (!handle || !password) {
56 return null;
57 }
58
59 return { handle, password };
60}