Authentication refactoring.
This commit is contained in:
@@ -1,25 +1,35 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { login } from "../../azure/index.ts";
|
||||
import type { ResourceName } from "../../azure/index.ts";
|
||||
import { loadAuthConfig } from "../../index.ts";
|
||||
|
||||
type LoginOptions = {
|
||||
resources?: string;
|
||||
useDeviceCode?: boolean;
|
||||
noBrowser?: boolean;
|
||||
browser?: string;
|
||||
browserName?: string;
|
||||
browserProfile?: string;
|
||||
};
|
||||
|
||||
export async function runLoginCommand(options: LoginOptions): Promise<unknown> {
|
||||
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");
|
||||
return login(
|
||||
|
||||
const result = await login(
|
||||
config.tenantId,
|
||||
config.clientId,
|
||||
options.resources,
|
||||
resources,
|
||||
Boolean(options.useDeviceCode),
|
||||
Boolean(options.noBrowser),
|
||||
options.browser,
|
||||
options.browserName,
|
||||
options.browserProfile,
|
||||
);
|
||||
) as LoginResult;
|
||||
|
||||
console.log(`Logged in as ${result.accountUpn ?? "<unknown>"} using ${result.flow} flow for resources: ${resources.join(",")}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user