-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[identity] Add interactive browser sample-dev
- Loading branch information
1 parent
2e6ba44
commit 5074be3
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
sdk/identity/identity/samples-dev/interactiveBrowserCredential.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |