MCPcopy Create free account
hub / github.com/ConsortiumAI/Consortium / doAuth

Function doAuth

packages/consortium-cli/src/ui/auth.ts:17–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15import { logger } from './logger';
16
17export async function doAuth(): Promise<Credentials | null> {
18 console.clear();
19 console.log('\nMobile Authentication\n');
20
21 // Generating ephemeral key
22 const secret = new Uint8Array(randomBytes(32));
23 const keypair = tweetnacl.box.keyPair.fromSecretKey(secret);
24
25 // Create a new authentication request
26 try {
27 await axios.post(`${configuration.serverUrl}/v1/auth/request`, {
28 publicKey: encodeBase64(keypair.publicKey),
29 supportsV2: true
30 });
31 } catch (error) {
32 console.log('Failed to create authentication request, please try again later.');
33 return null;
34 }
35
36 console.log('Scan this QR code with your Consortium mobile app:\n');
37
38 const authUrl = 'consortium://terminal?' + encodeBase64Url(keypair.publicKey);
39 displayQRCode(authUrl);
40
41 console.log('\nOr manually enter this URL:');
42 console.log(authUrl);
43 console.log('');
44
45 return await waitForAuthentication(keypair);
46}
47
48/**
49 * Wait for authentication to complete and return credentials

Callers 1

Calls 4

encodeBase64Function · 0.90
encodeBase64UrlFunction · 0.90
displayQRCodeFunction · 0.90
waitForAuthenticationFunction · 0.85

Tested by

no test coverage detected