Migrated to TypeScript.
This commit is contained in:
30
src/graph/auth.ts
Normal file
30
src/graph/auth.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { Client } from "@microsoft/microsoft-graph-client";
|
||||
import { acquireResourceTokenFromLogin } from "../azure/index.ts";
|
||||
|
||||
type GraphClientOptions = {
|
||||
tenantId?: string;
|
||||
clientId?: string;
|
||||
};
|
||||
|
||||
type GraphApiToken = {
|
||||
accessToken: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
export async function getGraphClient({ tenantId, clientId }: GraphClientOptions): Promise<{ graphApiToken: GraphApiToken; client: any }> {
|
||||
const graphApiToken = await acquireResourceTokenFromLogin({
|
||||
tenantId,
|
||||
clientId,
|
||||
resource: "graph",
|
||||
}) as GraphApiToken;
|
||||
|
||||
const client = Client.init({
|
||||
authProvider: (done) => {
|
||||
done(null, graphApiToken.accessToken);
|
||||
},
|
||||
});
|
||||
|
||||
return { graphApiToken, client };
|
||||
}
|
||||
Reference in New Issue
Block a user