Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Feb 3, 2024
1 parent 8aec092 commit ec9e0ad
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions api/src/routers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { authedProcedure, createTRPCRouter, publicProcedure } from "../trpc";
import { accounts, db, tenants } from "../db";
import { encodeId } from "../utils";
import { env } from "../env";
import { Client } from "@microsoft/microsoft-graph-client";
import {
TokenCredentialAuthenticationProvider,
TokenCredentialAuthenticationProviderOptions,
} from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials";
// import { Client } from "@microsoft/microsoft-graph-client";
// import {
// TokenCredentialAuthenticationProvider,
// TokenCredentialAuthenticationProviderOptions,
// } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials";
import { ClientSecretCredential } from "@azure/identity";

type UserResult = {
Expand Down Expand Up @@ -66,6 +66,8 @@ export const authRouter = createTRPCRouter({
}),

me: authedProcedure.query(async ({ ctx }) => {
// TODO: Can we share auth between requests???

let debug = undefined;
try {
console.log("A");
Expand All @@ -75,22 +77,22 @@ export const authRouter = createTRPCRouter({
env.INTUNE_CLIENT_SECRET
);

console.log("B");
const client = Client.initWithMiddleware({
debugLogging: true,
authProvider: new TokenCredentialAuthenticationProvider(
tokenCredential,
{
scopes: ["https://graph.microsoft.com/.default"],
getTokenOptions: {},
}
),
});

console.log("C");
let userDetails = await client.api("/me").get();
console.log("D", userDetails);
debug = userDetails;
// console.log("B");
// const client = Client.initWithMiddleware({
// debugLogging: true,
// authProvider: new TokenCredentialAuthenticationProvider(
// tokenCredential,
// {
// scopes: ["https://graph.microsoft.com/.default"],
// getTokenOptions: {},
// }
// ),
// });

// console.log("C");
// let userDetails = await client.api("/me").get();
// console.log("D", userDetails);
// debug = userDetails;
} catch (e) {
debug = (e as any).toString();
}
Expand Down

0 comments on commit ec9e0ad

Please sign in to comment.