Repository navigation
Expand file tree
/
Copy pathlogin.ts
More file actions
55 lines (53 loc) · 1.77 KB
/
Copy pathlogin.ts
File metadata and controls
55 lines (53 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/** The TUI's login: the browser OAuth flow, shown on the auth screen, as a credentials provider. */
import type {
CredentialsProvider,
ResolvedProgramCredentials,
WizardSession,
} from '@programs/types';
import { analytics } from '@utils/analytics';
import { logToFile } from '@utils/debug';
import type { WizardStore } from '@tui/store';
import { getOrAskForProjectData } from './project-data.js';
/** Log in once through OAuth for the session's launch values. */
export async function oauthLogin(
session: WizardSession,
programId: string,
store: WizardStore,
completionScopeOptional?: boolean,
): Promise<ResolvedProgramCredentials> {
logToFile('[agent-runner] starting OAuth');
const data = await getOrAskForProjectData({
store,
signup: session.signup,
projectId: session.projectId,
email: session.email,
region: session.region,
baseUrl: session.baseUrl,
localMcp: session.localMcp,
programId,
completionScopeOptional,
});
analytics.wizardCapture('auth complete', { project_id: data.projectId });
return {
posthog: {
accessToken: data.accessToken,
refreshToken: data.refreshToken,
expiresAt: data.expiresAt,
oauthClientId: data.oauthClientId,
projectApiKey: data.projectApiKey,
host: data.host,
projectId: data.projectId,
missingScopes: data.missingScopes,
},
project: data.project,
apiUser: data.user,
roleAtOrganization: data.roleAtOrganization,
};
}
/** The OAuth login as `runProgram`'s provider, reading the store's session when it is asked. */
export function oauthCredentials(store: WizardStore): CredentialsProvider {
return {
resolve: (programId, { completionScopeOptional }) =>
oauthLogin(store.session, programId, store, completionScopeOptional),
};
}