Skip to content

Commit

Permalink
[identity] Add interactive browser sample-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mpodwysocki committed Nov 7, 2023
1 parent 2e6ba44 commit 5074be3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions sdk/identity/identity/samples-dev/interactiveBrowserCredential.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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);
});

0 comments on commit 5074be3

Please sign in to comment.