From 5074be32fa3b983c4daa5f6bab23226898819baa Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 7 Nov 2023 18:40:52 -0500 Subject: [PATCH] [identity] Add interactive browser sample-dev --- .../interactiveBrowserCredential.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 sdk/identity/identity/samples-dev/interactiveBrowserCredential.ts diff --git a/sdk/identity/identity/samples-dev/interactiveBrowserCredential.ts b/sdk/identity/identity/samples-dev/interactiveBrowserCredential.ts new file mode 100644 index 000000000000..9563c1176480 --- /dev/null +++ b/sdk/identity/identity/samples-dev/interactiveBrowserCredential.ts @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @summary Authenticates using Interactive Browser Credential + */ + +import { + InteractiveBrowserCredential, + InteractiveBrowserCredentialNodeOptions, +} from "@azure/identity"; +import dotenv from "dotenv"; + +dotenv.config(); + +const clientId = process.env.AZURE_CLIENT_ID; // The app registration client Id in the Microsoft Entra tenant +const tenantId = process.env.AZURE_TENANT_ID; // The tenant ID in Microsoft Entra ID + +async function main(): Promise { + const credential = new InteractiveBrowserCredential({ + clientId, + tenantId, + redirectUri: "http://localhost:1337", + } as InteractiveBrowserCredentialNodeOptions); + + const { token } = await credential.getToken("https://graph.microsoft.com/User.Read"); + console.log(`Token: ${token}`); +} + +main().catch((err) => { + console.error("The sample encountered an error:", err); +});