A work-in-progress, horribly overpowered CLI for Ozone
1import { AtpAgent } from "@atproto/api";
2import { parseArgs } from "@std/cli";
3
4export const loginToService = async () => {
5 const {
6 username = Deno.env.get("ATP_USERNAME"),
7 password = Deno.env.get("ATP_PASSWORD"),
8 service = Deno.env.get("SERVICE_URI") ?? "https://bsky.social",
9 proxy = Deno.env.get("SERVICE_DID"),
10 } = parseArgs(Deno.args);
11
12 const agent = new AtpAgent({ service });
13 agent.configureProxy(proxy);
14
15 try {
16 await agent.login({ identifier: username, password });
17 } catch (e) {
18 console.dir(e);
19 if (e instanceof Error && e.name === "AuthFactorTokenRequiredError") {
20 let authFactorToken;
21
22 do {
23 authFactorToken = prompt(
24 `Check your email for a login token and enter it below:`
25 );
26 } while (!authFactorToken);
27
28 try {
29 await agent.login({
30 identifier: username,
31 password,
32 authFactorToken,
33 });
34 } catch (e) {
35 console.error(e);
36 }
37 }
38 }
39 return agent;
40};