Update: devops submodule convertion to new simpler auth model.
This commit is contained in:
@@ -1,27 +1,18 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
export * from "./auth.ts";
|
||||
export * from "./app.ts";
|
||||
export * from "./sp.ts";
|
||||
|
||||
import { loadAuthConfig, loadConfig } from "../index.ts";
|
||||
import { Client, AuthProvider } from "@microsoft/microsoft-graph-client";
|
||||
|
||||
import { getMsalAuthProvider, getAzureIdentityAuthProvider } from "./auth.ts";
|
||||
import { Client } from "@microsoft/microsoft-graph-client";
|
||||
import { RESOURCE_SCOPE_BY_NAME, getTokenCredential } from "../azure/index.ts";
|
||||
|
||||
export async function getGraphClient(): Promise<Client> {
|
||||
const config = await loadConfig();
|
||||
|
||||
let authProvider: AuthProvider;
|
||||
|
||||
if (config.authMode === "azure-identity") {
|
||||
authProvider = getAzureIdentityAuthProvider();
|
||||
} else {
|
||||
const authConfig = await loadAuthConfig("public-config");
|
||||
authProvider = getMsalAuthProvider(authConfig.tenantId, authConfig.clientId);
|
||||
}
|
||||
|
||||
return Client.init({
|
||||
authProvider: authProvider,
|
||||
authProvider: (done) => {
|
||||
void getTokenCredential()
|
||||
.then((credential) => credential.getToken(RESOURCE_SCOPE_BY_NAME.graph))
|
||||
.then((accessToken) => done(null, accessToken?.token ?? null))
|
||||
.catch((err) => done(err as Error, null));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user