Skip to content

Commit 4737319

Browse files
committed
Merging changes synced from https://github.com/MicrosoftDocs/azure-docs-pr (branch live)
2 parents 55b32f4 + 04420fb commit 4737319

File tree

390 files changed

+4085
-1039
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

390 files changed

+4085
-1039
lines changed

.openpublishing.redirection.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@
6565
"redirect_url": "/previous-versions/azure/machine-learning/classic/deploy-consume-web-service-guide",
6666
"redirect_document_id": false
6767
},
68-
{
69-
"source_path": "articles/machine-learning/classic/deploy-with-resource-manager-template.md",
70-
"redirect_url": "/previous-versions/azure/machine-learning/classic/deploy-with-resource-manager-template",
71-
"redirect_document_id": false
72-
},
7368
{
7469
"source_path": "articles/machine-learning/classic/evaluate-model-performance.md",
7570
"redirect_url": "/previous-versions/azure/machine-learning/classic/evaluate-model-performance",
@@ -34570,7 +34565,7 @@
3457034565
},
3457134566
{
3457234567
"source_path_from_root": "/articles/security/fundamentals/channel-nine.md",
34573-
"redirect_url": "https://channel9.msdn.com/",
34568+
"redirect_url": "/teamblog/channel9joinedmicrosoftlearn/",
3457434569
"redirect_document_id": false
3457534570
},
3457634571
{
@@ -41793,11 +41788,6 @@
4179341788
"redirect_url": "/azure/cognitive-services/Content-Moderator/overview",
4179441789
"redirect_document_id": false
4179541790
},
41796-
{
41797-
"source_path_from_root": "/articles/cognitive-services/Content-Moderator/facebook-post-moderation.md",
41798-
"redirect_url": "/azure/cognitive-services/Content-Moderator/overview",
41799-
"redirect_document_id": false
41800-
},
4180141791
{
4180241792
"source_path_from_root": "/articles/cognitive-services/Content-Moderator/moderation-jobs-quickstart-dotnet.md",
4180341793
"redirect_url": "/azure/cognitive-services/Content-Moderator/overview",

articles/active-directory-b2c/solution-articles.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Azure Active Directory B2C (Azure AD B2C) enables organizations to implement bus
1818

1919
| Title | Medium | Description |
2020
| ----- | ------ |----------- |
21-
| [Customer Identity Management with Azure AD B2C](https://channel9.msdn.com/Shows/On-NET/Customer-Identity-Management-with-Azure-AD-B2C) | Video (20 minutes) | In this overview of the service, Parakh Jain ([@jainparakh](https://twitter.com/jainparakh)) from the Azure AD B2C team provides us an overview of how the service works, and also show how we can quickly connect B2C to an ASP.NET Core application. |
21+
| [Customer Identity Management with Azure AD B2C](/Shows/On-NET/Customer-Identity-Management-with-Azure-AD-B2C) | Video (20 minutes) | In this overview of the service, Parakh Jain ([@jainparakh](https://twitter.com/jainparakh)) from the Azure AD B2C team provides us an overview of how the service works, and also show how we can quickly connect B2C to an ASP.NET Core application. |
2222
| [Benefits of using Azure AD B2C](https://aka.ms/b2coverview) | PDF | Understand the benefits and common scenarios of Azure AD B2C, and how your application(s) can leverage this CIAM service. |
2323
| [Gaining Expertise in Azure AD B2C: A Course for Developers](https://aka.ms/learnAADB2C) | PDF | This end-to-end course takes developers through a complete journey on developing applications with Azure AD B2C as the authentication mechanism. Ten in-depth modules with labs cover everything from setting up an Azure subscription to creating custom policies that define the journeys that engage your customers. |
2424
| [Enabling partners, Suppliers, and Customers to Access Applications with Azure active Directory](https://aka.ms/aadexternalidentities) | PDF | Every organization’s success, regardless of its size, industry, or compliance and security posture, relies on organizational ability to collaborate with other organizations and connect with customers.<br><br>Bringing together Azure AD, Azure AD B2C, and Azure AD B2B Collaboration, this guide details the business value and the mechanics of building an application or web experience that provides a consolidated authentication experience tailored to the contexts of your employees, business partners and suppliers, and customers. |

articles/active-directory/develop/TOC.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,11 @@
2525
- name: Web app
2626
href: web-app-quickstart.md
2727
- name: Web API
28-
items:
29-
- name: ASP.NET
30-
href: quickstart-v2-dotnet-native-aspnet.md
31-
- name: ASP.NET Core
32-
href: quickstart-v2-aspnet-core-web-api.md
33-
- name: Mobile and desktop
34-
items:
35-
- name: Android
36-
href: quickstart-v2-android.md
37-
- name: iOS and macOS
38-
href: quickstart-v2-ios.md
39-
- name: Universal Windows Platform
40-
displayName: UWP
41-
href: quickstart-v2-uwp.md
42-
- name: Windows Desktop .NET
43-
href: quickstart-v2-windows-desktop.md
44-
- name: Node.js Electron
45-
href: quickstart-v2-nodejs-desktop.md
28+
href: web-api-quickstart.md
29+
- name: Mobile app
30+
href: mobile-app-quickstart.md
31+
- name: Desktop app
32+
href: desktop-app-quickstart.md
4633
- name: Daemon or back-end service
4734
href: console-app-quickstart.md
4835
- name: Tutorials
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: "Quickstart: Sign in users and call Microsoft Graph in a desktop app | Azure"
3+
titleSuffix: Microsoft identity platform
4+
description: In this quickstart, learn how a desktop application can get an access token and call an API protected by the Microsoft identity platform.
5+
services: active-directory
6+
author: Dickson-Mwendia
7+
manager: CelesteDG
8+
9+
ms.service: active-directory
10+
ms.subservice: develop
11+
ms.topic: quickstart
12+
ms.workload: identity
13+
ms.date: 01/14/2022
14+
ms.author: dmwendia
15+
ms.custom: aaddev, identityplatformtop40, "scenarios:getting-started", mode-api
16+
zone_pivot_groups: desktop-app-quickstart
17+
#Customer intent: As an application developer, I want to learn how my desktop application can get an access token and call an API that's protected by the Microsoft identity platform.
18+
---
19+
20+
# Quickstart: Acquire a token and call Microsoft Graph API from a desktop application
21+
22+
::: zone pivot="devlang-uwp"
23+
[!INCLUDE [Universal Windows Platform](./includes/desktop-app/quickstart-uwp.md)]
24+
::: zone-end
25+
26+
::: zone pivot="devlang-windows-desktop"
27+
[!INCLUDE [Windows Desktop .NET](./includes/desktop-app/quickstart-windows-desktop.md)]
28+
::: zone-end
29+
30+
::: zone pivot="devlang-nodejs-electron"
31+
[!INCLUDE [Node.js Electron](./includes/desktop-app/quickstart-nodejs-electron.md)]
32+
::: zone-end
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
---
2+
title: "Quickstart: Call Microsoft Graph from a Node.js desktop app | Azure"
3+
titleSuffix: Microsoft identity platform
4+
description: In this quickstart, you learn how a Node.js Electron desktop application can sign-in users and get an access token to call an API protected by a Microsoft identity platform endpoint
5+
services: active-directory
6+
author: mmacy
7+
manager: CelesteDG
8+
ms.service: active-directory
9+
ms.subservice: develop
10+
ms.topic: include
11+
ms.date: 01/14/2022
12+
ms.author: marsma
13+
ms.custom: mode-api
14+
#Customer intent: As an application developer, I want to learn how my Node.js Electron desktop application can get an access token and call an API that's protected by a Microsoft identity platform endpoint.
15+
---
16+
17+
In this quickstart, you download and run a code sample that demonstrates how an Electron desktop application can sign in users and acquire access tokens to call the Microsoft Graph API.
18+
19+
This quickstart uses the [Microsoft Authentication Library for Node.js (MSAL Node)](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-node) with the [authorization code flow with PKCE](../../v2-oauth2-auth-code-flow.md).
20+
21+
## Prerequisites
22+
23+
* [Node.js](https://nodejs.org/en/download/)
24+
* [Visual Studio Code](https://code.visualstudio.com/download) or another code editor
25+
26+
27+
## Register and download the sample application
28+
29+
Follow the steps below to get started.
30+
31+
#### Step 1: Register the application
32+
To register your application and add the app's registration information to your solution manually, follow these steps:
33+
34+
1. Sign in to the [Azure portal](https://portal.azure.com/).
35+
1. If you have access to multiple tenants, use the **Directories + subscriptions** filter :::image type="icon" source="./../../media/common/portal-directory-subscription-filter.png" border="false"::: in the top menu to switch to the tenant in which you want to register the application.
36+
1. Search for and select **Azure Active Directory**.
37+
1. Under **Manage**, select **App registrations** > **New registration**.
38+
1. Enter a **Name** for your application, for example `msal-node-desktop`. Users of your app might see this name, and you can change it later.
39+
1. Select **Register** to create the application.
40+
1. Under **Manage**, select **Authentication**.
41+
1. Select **Add a platform** > **Mobile and desktop applications**.
42+
1. In the **Redirect URIs** section, enter `msal://redirect`.
43+
1. Select **Configure**.
44+
45+
#### Step 2: Download the Electron sample project
46+
47+
48+
[Download the code sample](https://github.com/azure-samples/ms-identity-javascript-nodejs-desktop/archive/main.zip)
49+
50+
#### Step 3: Configure the Electron sample project
51+
52+
1. Extract the zip file to a local folder close to the root of the disk, for example, *C:/Azure-Samples*.
53+
1. Edit *.env* and replace the values of the fields `TENANT_ID` and `CLIENT_ID` with the following snippet:
54+
55+
```
56+
"TENANT_ID": "Enter_the_Tenant_Id_Here",
57+
"CLIENT_ID": "Enter_the_Application_Id_Here"
58+
```
59+
Where:
60+
- `Enter_the_Application_Id_Here` - is the **Application (client) ID** for the application you registered.
61+
- `Enter_the_Tenant_Id_Here` - replace this value with the **Tenant Id** or **Tenant name** (for example, contoso.microsoft.com)
62+
63+
> [!TIP]
64+
> To find the values of **Application (client) ID**, **Directory (tenant) ID**, go to the app's **Overview** page in the Azure portal.
65+
66+
#### Step 4: Run the application
67+
68+
You'll need to install the dependencies of this sample once:
69+
70+
```console
71+
npm install
72+
```
73+
74+
Then, run the application via command prompt or console:
75+
76+
```console
77+
npm start
78+
```
79+
80+
You should see application's UI with a **Sign in** button.
81+
82+
## About the code
83+
84+
Below, some of the important aspects of the sample application are discussed.
85+
86+
### MSAL Node
87+
88+
[MSAL Node](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-node) is the library used to sign in users and request tokens used to access an API protected by Microsoft identity platform. For more information on how to use MSAL Node with desktop apps, see [this article](../../scenario-desktop-overview.md).
89+
90+
You can install MSAL Node by running the following npm command.
91+
92+
```console
93+
npm install @azure/msal-node --save
94+
```
95+
96+
### MSAL initialization
97+
98+
You can add the reference for MSAL Node by adding the following code:
99+
100+
```javascript
101+
const { PublicClientApplication } = require('@azure/msal-node');
102+
```
103+
104+
Then, initialize MSAL using the following code:
105+
106+
```javascript
107+
const MSAL_CONFIG = {
108+
auth: {
109+
clientId: "Enter_the_Application_Id_Here",
110+
authority: "https://login.microsoftonline.com/Enter_the_Tenant_Id_Here",
111+
},
112+
};
113+
114+
const pca = new PublicClientApplication(MSAL_CONFIG);
115+
```
116+
117+
> | Where: |Description |
118+
> |---------|---------|
119+
> | `clientId` | Is the **Application (client) ID** for the application registered in the Azure portal. You can find this value in the app's **Overview** page in the Azure portal. |
120+
> | `authority` | The STS endpoint for user to authenticate. Usually `https://login.microsoftonline.com/{tenant}` for public cloud, where {tenant} is the name of your tenant or your tenant Id.|
121+
122+
### Requesting tokens
123+
124+
In the first leg of authorization code flow with PKCE, prepare and send an authorization code request with the appropriate parameters. Then, in the second leg of the flow, listen for the authorization code response. Once the code is obtained, exchange it to obtain a token.
125+
126+
```javascript
127+
// The redirect URI you setup during app registration with a custom file protocol "msal"
128+
const redirectUri = "msal://redirect";
129+
130+
const cryptoProvider = new CryptoProvider();
131+
132+
const pkceCodes = {
133+
challengeMethod: "S256", // Use SHA256 Algorithm
134+
verifier: "", // Generate a code verifier for the Auth Code Request first
135+
challenge: "" // Generate a code challenge from the previously generated code verifier
136+
};
137+
138+
/**
139+
* Starts an interactive token request
140+
* @param {object} authWindow: Electron window object
141+
* @param {object} tokenRequest: token request object with scopes
142+
*/
143+
async function getTokenInteractive(authWindow, tokenRequest) {
144+
145+
/**
146+
* Proof Key for Code Exchange (PKCE) Setup
147+
*
148+
* MSAL enables PKCE in the Authorization Code Grant Flow by including the codeChallenge and codeChallengeMethod
149+
* parameters in the request passed into getAuthCodeUrl() API, as well as the codeVerifier parameter in the
150+
* second leg (acquireTokenByCode() API).
151+
*/
152+
153+
const {verifier, challenge} = await cryptoProvider.generatePkceCodes();
154+
155+
pkceCodes.verifier = verifier;
156+
pkceCodes.challenge = challenge;
157+
158+
const authCodeUrlParams = {
159+
redirectUri: redirectUri
160+
scopes: tokenRequest.scopes,
161+
codeChallenge: pkceCodes.challenge, // PKCE Code Challenge
162+
codeChallengeMethod: pkceCodes.challengeMethod // PKCE Code Challenge Method
163+
};
164+
165+
const authCodeUrl = await pca.getAuthCodeUrl(authCodeUrlParams);
166+
167+
// register the custom file protocol in redirect URI
168+
protocol.registerFileProtocol(redirectUri.split(":")[0], (req, callback) => {
169+
const requestUrl = url.parse(req.url, true);
170+
callback(path.normalize(`${__dirname}/${requestUrl.path}`));
171+
});
172+
173+
const authCode = await listenForAuthCode(authCodeUrl, authWindow); // see below
174+
175+
const authResponse = await pca.acquireTokenByCode({
176+
redirectUri: redirectUri,
177+
scopes: tokenRequest.scopes,
178+
code: authCode,
179+
codeVerifier: pkceCodes.verifier // PKCE Code Verifier
180+
});
181+
182+
return authResponse;
183+
}
184+
185+
/**
186+
* Listens for auth code response from Azure AD
187+
* @param {string} navigateUrl: URL where auth code response is parsed
188+
* @param {object} authWindow: Electron window object
189+
*/
190+
async function listenForAuthCode(navigateUrl, authWindow) {
191+
192+
authWindow.loadURL(navigateUrl);
193+
194+
return new Promise((resolve, reject) => {
195+
authWindow.webContents.on('will-redirect', (event, responseUrl) => {
196+
try {
197+
const parsedUrl = new URL(responseUrl);
198+
const authCode = parsedUrl.searchParams.get('code');
199+
resolve(authCode);
200+
} catch (err) {
201+
reject(err);
202+
}
203+
});
204+
});
205+
}
206+
```
207+
208+
> |Where:| Description |
209+
> |---------|---------|
210+
> | `authWindow` | Current Electron window in process. |
211+
> | `tokenRequest` | Contains the scopes being requested, such as `"User.Read"` for Microsoft Graph or `"api://<Application ID>/access_as_user"` for custom web APIs. |
212+
213+
## Next steps
214+
215+
To learn more about Electron desktop app development with MSAL Node, see the tutorial:
216+
217+
> [!div class="nextstepaction"]
218+
> [Tutorial: Sign in users and call the Microsoft Graph API in an Electron desktop app](../../tutorial-v2-nodejs-desktop.md)

0 commit comments

Comments
 (0)