36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
// SPDX-License-Identifier: MIT
|
|
|
|
import { login } from "../../azure/index.ts";
|
|
import type { ResourceName } from "../../azure/index.ts";
|
|
import { loadAuthConfig } from "../../index.ts";
|
|
|
|
type LoginOptions = {
|
|
useDeviceCode?: boolean;
|
|
noBrowser?: boolean;
|
|
browserName?: string;
|
|
browserProfile?: string;
|
|
};
|
|
|
|
type LoginResult = {
|
|
accountUpn: string | null;
|
|
resources: Array<{ resource: string; expiresOn: string | null }>;
|
|
flow: "device-code" | "interactive";
|
|
browserLaunchAttempted: boolean;
|
|
};
|
|
|
|
export async function runLoginCommand(resources: ResourceName[], options: LoginOptions): Promise<void> {
|
|
const config = await loadAuthConfig("public-config");
|
|
|
|
const result = await login(
|
|
config.tenantId,
|
|
config.clientId,
|
|
resources,
|
|
Boolean(options.useDeviceCode),
|
|
Boolean(options.noBrowser),
|
|
options.browserName,
|
|
options.browserProfile,
|
|
) as LoginResult;
|
|
|
|
console.log(`Logged in as ${result.accountUpn ?? "<unknown>"} using ${result.flow} flow for resources: ${resources.join(",")}`);
|
|
}
|