Skip to content

Commit

Permalink
Edge function counter
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Feb 3, 2024
1 parent a494c3e commit 9efd594
Showing 1 changed file with 54 additions and 44 deletions.
98 changes: 54 additions & 44 deletions api/src/routers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ 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 { ClientSecretCredential } from "@azure/identity";
import { AuthenticationProvider } from "@microsoft/microsoft-graph-client";
// import {
// TokenCredentialAuthenticationProvider,
// TokenCredentialAuthenticationProviderOptions,
// } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials";
// import { ClientSecretCredential } from "@azure/identity";
// import { AuthenticationProvider } from "@microsoft/microsoft-graph-client";

type UserResult = {
id: string;
Expand All @@ -33,11 +33,13 @@ const fetchTenants = async (session_id: number) =>
id: encodeId("tenant", tenant.id),
}));

class MyAuthenticationProvider implements AuthenticationProvider {
public async getAccessToken(): Promise<string> {
return "todo";
}
}
// class MyAuthenticationProvider implements AuthenticationProvider {
// public async getAccessToken(): Promise<string> {
// return "todo";
// }
// }

let testingGlobal = 0;

export const authRouter = createTRPCRouter({
login: publicProcedure
Expand Down Expand Up @@ -75,39 +77,47 @@ export const authRouter = createTRPCRouter({
me: authedProcedure.query(async ({ ctx }) => {
// TODO: Can we share auth between requests???

let debug = undefined;
try {
console.log("A");
const tokenCredential = new ClientSecretCredential(
env.INTUNE_TENANT,
env.INTUNE_CLIENT_ID,
env.INTUNE_CLIENT_SECRET
);

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

// const client = Client.initWithMiddleware({
// debugLogging: true,
// authProvider: new MyAuthenticationProvider(),
// });

console.log("C");
let userDetails = await client.api("/me").get();
console.log("D", userDetails);
debug = userDetails;
} catch (e) {
debug = (e as any).toString();
}
// let debug = undefined;
// try {
// console.log("A");
// const tokenCredential = new ClientSecretCredential(
// env.INTUNE_TENANT,
// env.INTUNE_CLIENT_ID,
// env.INTUNE_CLIENT_SECRET
// );

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

// // const client = Client.initWithMiddleware({
// // debugLogging: true,
// // authProvider: new MyAuthenticationProvider(),
// // });

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

if (!("testingTwo" in globalThis)) globalThis.testingTwo = 0;
const debug = {
a: testingGlobal,
b: globalThis.testingTwo,
};
testingGlobal += 1;
globalThis.testingTwo += 1;

const session = ctx.session.data;
return {
Expand Down

0 comments on commit 9efd594

Please sign in to comment.