You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Angular single-page application using MSAL Angular to sign-in users against Azure AD B2C
2
23
3
-
1.[Overview](#overview)
4
-
1.[Scenario](#scenario)
5
-
1.[Contents](#contents)
6
-
1.[Prerequisites](#prerequisites)
7
-
1.[Setup](#setup)
8
-
1.[Registration](#registration)
9
-
1.[Running the sample](#running-the-sample)
10
-
1.[Explore the sample](#explore-the-sample)
11
-
1.[About the code](#about-the-code)
12
-
1.[More information](#more-information)
13
-
1.[Community Help and Support](#community-help-and-support)
14
-
1.[Contributing](#contributing)
24
+
*[Overview](#overview)
25
+
*[Scenario](#scenario)
26
+
*[Contents](#contents)
27
+
*[Prerequisites](#prerequisites)
28
+
*[Explore the sample](#explore-the-sample)
29
+
*[Troubleshooting](#troubleshooting)
30
+
*[About the code](#about-the-code)
31
+
*[Next Steps](#next-steps)
32
+
*[Contributing](#contributing)
15
33
16
34
## Overview
17
35
18
36
This sample demonstrates an Angular single-page application (SPA) that lets users sign-in with [Azure AD B2C](https://azure.microsoft.com/services/active-directory/external-identities/b2c/) using the [Microsoft Authentication Library for Angular](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-angular) (MSAL Angular).
19
37
20
38
Here you'll learn about [ID Tokens](https://docs.microsoft.com/azure/active-directory-b2c/tokens-overview#token-types), [OIDC Scopes](https://docs.microsoft.com/azure/active-directory/develop/v2-permissions-and-consent#openid-connect-scopes), [external identity providers](https://docs.microsoft.com/azure/active-directory-b2c/technical-overview#external-identity-providers), [consumer social accounts](https://docs.microsoft.com/azure/active-directory-b2c/technical-overview#consumer-accounts), [single-sign on (SSO)](https://docs.microsoft.com/azure/active-directory-b2c/session-overview), **silent requests** and more.
21
39
40
+
> :information_source: See the community call: [Deep dive on using MSAL.js to integrate Angular single-page applications with Azure Active Directory](https://www.youtube.com/watch?v=EJey9KP1dZA)
41
+
22
42
## Scenario
23
43
24
44
1. The client Angular SPA uses **MSAL Angular** to obtain an ID Token from **Azure AD B2C**.
@@ -32,24 +52,28 @@ Here you'll learn about [ID Tokens](https://docs.microsoft.com/azure/active-dire
|`src/app/app-routing.module.ts`| Configure your MSAL-Guard here. |
55
+
|`src/app/app-routing.module.ts`| Configure your MSALGuard here. |
36
56
37
57
## Prerequisites
38
58
39
-
- An **Azure AD B2C** tenant. For more information see: [How to get an Azure AD B2C tenant](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-tenant)
40
-
- A user account in your **Azure AD B2C** tenant.
59
+
*[Node.js](https://nodejs.org/en/download/) must be installed to run this sample.
60
+
*[Visual Studio Code](https://code.visualstudio.com/download) is recommended for running and editing this sample.
61
+
*[VS Code Azure Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-node-azure-pack) extension is recommended for interacting with Azure through VS Code Interface.
62
+
* A modern web browser. This sample uses **ES6** conventions and will not run on **Internet Explorer**.
63
+
* An **Azure AD B2C** tenant. For more information, see: [How to get an Azure AD B2C tenant](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-tenant)
or download and extract the repository *.zip* file.
53
77
54
78
> :warning: To avoid path length limitations on Windows, we recommend cloning into a directory near the root of your drive.
55
79
@@ -61,38 +85,42 @@ or download and extract the repository .zip file.
61
85
npm install
62
86
```
63
87
64
-
##Registration
88
+
### Step 3: Register the sample application in your tenant
65
89
66
-
:warning: This sample comes with a pre-registered application for demo purposes. If you would like to use your own **Azure AD B2C** tenant and application, follow the steps below to register and configure the application on **Azure portal**. Otherwise, continue with the steps for [Running the sample](#running-the-sample).
90
+
:warning: This sample comes with a pre-registered application for demo purposes. If you would like to use your own **Azure AD B2C** tenant and application, follow the steps below to register and configure the application on **Azure portal**. Otherwise, continue with the steps for [Explore the sample](#explore-the-sample).
67
91
68
-
### Choose the Azure AD tenant where you want to create your applications
92
+
####Choose the Azure AD B2C tenant where you want to create your applications
69
93
70
94
As a first step you'll need to:
71
95
72
96
1. Sign in to the [Azure portal](https://portal.azure.com).
73
97
1. If your account is present in more than one Azure AD B2C tenant, select your profile at the top right corner in the menu on top of the page, and then **switch directory** to change your portal session to the desired Azure AD B2C tenant.
74
98
75
-
### Create User Flows and Custom Policies
99
+
####Create User Flows and Custom Policies
76
100
77
101
Please refer to: [Tutorial: Create user flows in Azure Active Directory B2C](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-user-flows)
78
102
79
-
### Add External Identity Providers
103
+
####Add External Identity Providers
80
104
81
105
Please refer to: [Tutorial: Add identity providers to your applications in Azure Active Directory B2C](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-add-identity-providers)
82
106
83
-
### Register the app (msal-angular-spa)
107
+
####Register the app (msal-angular-spa)
84
108
85
-
1. Navigate to the [Azure portal](https://portal.azure.com) and select the **Azure AD B2C** service.
109
+
1. Navigate to the [Azure portal](https://portal.azure.com) and select the **Azure Active Directory B2C** service.
86
110
1. Select the **App Registrations** blade on the left, then select **New registration**.
87
111
1. In the **Register an application page** that appears, enter your application's registration information:
88
-
- In the **Name** section, enter a meaningful application name that will be displayed to users of the app, for example `msal-angular-spa`.
89
-
- Under **Supported account types**, select **Accounts in any identity provider or organizational directory (for authenticating users with user flows)**.
90
-
- In the **Redirect URI** section, select **Single-page application** in the combo-box and enter the following redirect URI: `http://localhost:4200`.
91
-
1. Select **Register** to create the application.
92
-
1. In the app's registration screen, find and note the **Application (client) ID**. You use this value in your app's configuration file(s) later in your code.
93
-
1. Select **Save** to save your changes.
94
-
95
-
#### Configure the app (msal-angular-spa) to use your app registration
112
+
1. In the **Name** section, enter a meaningful application name that will be displayed to users of the app, for example `msal-angular-spa`.
113
+
1. Under **Supported account types**, select **Accounts in any identity provider or organizational directory (for authenticating users with user flows)**
114
+
1. Select **Register** to create the application.
115
+
1. In the **Overview** blade, find and note the **Application (client) ID**. You use this value in your app's configuration file(s) later in your code.
116
+
1. In the app's registration screen, select the **Authentication** blade to the left.
117
+
1. If you don't have a platform added, select **Add a platform** and select the **Single-page application** option.
118
+
1. In the **Redirect URI** section enter the following redirect URIs:
119
+
1.`http://localhost:4200`
120
+
1.`http://localhost:4200/auth`
121
+
1. Click **Save** to save your changes.
122
+
123
+
##### Configure the app (msal-angular-spa) to use your app registration
96
124
97
125
Open the project in your IDE (like Visual Studio or Visual Studio Code) to configure the code.
98
126
@@ -107,7 +135,9 @@ To setup your B2C user-flows, do the following:
107
135
1. Find the key `authorities` and populate it with your policy authority strings e.g. `https://<your-tenant-name>.b2clogin.com/<your-tenant-name>.onmicrosoft.com/b2c_1_susi`.
108
136
1. Find the key `authorityDomain` and populate it with the domain portion of your authority string e.g. `<your-tenant-name>.b2clogin.com`.
109
137
110
-
## Running the sample
138
+
### Step 4: Running the sample
139
+
140
+
From your shell or command line, execute the following commands:
111
141
112
142
```console
113
143
cd 1-Authentication/2-sign-in-b2c/SPA
@@ -123,12 +153,27 @@ To setup your B2C user-flows, do the following:
123
153
124
154
> :information_source: Did the sample not work for you as expected? Then please reach out to us using the [GitHub Issues](../../../../issues) page.
125
155
126
-
> :information_source: if you believe your issue is with the B2C service itself rather than with the sample, please file a support ticket with the B2C team by following the instructions [here](https://docs.microsoft.com/en-us/azure/active-directory-b2c/support-options).
156
+
> :information_source: if you believe your issue is with the B2C service itself rather than with the sample, please file a support ticket with the B2C team by following the instructions [here](https://docs.microsoft.com/azure/active-directory-b2c/support-options).
127
157
128
158
## We'd love your feedback!
129
159
130
160
Were we successful in addressing your learning objective? Consider taking a moment to [share your experience with us](https://forms.office.com/Pages/ResponsePage.aspx?id=v4j5cvGGr0GRqy180BHbR73pcsbpbxNJuZCMKN0lURpUOU5PNlM4MzRRV0lETkk2ODBPT0NBTEY5MCQlQCN0PWcu).
131
161
162
+
## Troubleshooting
163
+
164
+
<details>
165
+
<summary>Expand for troubleshooting info</summary>
166
+
167
+
Use [Stack Overflow](http://stackoverflow.com/questions/tagged/msal) to get support from the community.
168
+
Ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before.
169
+
Make sure that your questions or comments are tagged with [`azure-active-directory``azure-ad-b2c``ms-identity``adal``msal`].
170
+
171
+
If you find a bug in the sample, raise the issue on [GitHub Issues](../../../../issues).
172
+
173
+
To provide feedback on or suggest features for Azure Active Directory, visit [User Voice page](https://feedback.azure.com/forums/169401-azure-active-directory).
174
+
175
+
</details>
176
+
132
177
## About the code
133
178
134
179
MSAL Angular is a wrapper around MSAL.js (i.e. *msal-browser*). As such, many of MSAL.js's public APIs are also available to use with MSAL Angular, while MSAL Angular itself offers additional [public APIs](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/docs/v2-docs/public-apis.md).
@@ -278,11 +323,11 @@ For more information, see: [Events in MSAL Angular v2](https://github.com/AzureA
FormoreinformationabouthowOAuth2.0protocolsworkinthisscenarioandotherscenarios, see [AuthenticationScenariosforAzureAD](https://docs.microsoft.com/azure/active-directory/develop/authentication-flows-app-scenarios).
317
-
318
-
## CommunityHelpandSupport
347
+
## NextSteps
319
348
320
-
Use [StackOverflow](http://stackoverflow.com/questions/tagged/msal) to get support from the community.
Ifyou'd like to contribute to this sample, see [CONTRIBUTING.MD](/CONTRIBUTING.md).
331
357
332
-
Thisprojecthasadoptedthe [MicrosoftOpenSourceCodeofConduct](https://opensource.microsoft.com/codeofconduct/). For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
358
+
Thisprojecthasadoptedthe [MicrosoftOpenSourceCodeofConduct](https://opensource.microsoft.com/codeofconduct/). For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
0 commit comments