Skip to content

Commit 8c2f56b

Browse files
authored
Merge pull request #104033 from jasonnutter/angular-quickstart
Initial MSAL Angular quickstart
2 parents a920335 + ce53d41 commit 8c2f56b

10 files changed

+624
-61
lines changed

articles/active-directory/develop/TOC.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
- name: Single-page apps
2727
displayName: SPA
2828
items:
29+
- name: Angular
30+
href: quickstart-v2-angular.md
2931
- name: JavaScript
3032
href: quickstart-v2-javascript.md
3133
- name: Web apps
@@ -69,6 +71,8 @@
6971
- name: Single-page apps
7072
displayName: SPA
7173
items:
74+
- name: Angular
75+
href: tutorial-v2-angular.md
7276
- name: JavaScript
7377
href: tutorial-v2-javascript-spa.md
7478
- name: Web apps
@@ -581,4 +585,4 @@
581585
href: https://docs.microsoft.com/azure/active-directory/managed-service-identity/overview
582586
- name: Getting help
583587
displayName: support, help options
584-
href: developer-support-help-options.md
588+
href: developer-support-help-options.md

articles/active-directory/develop/index.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ landingContent:
4747
links:
4848
- text: JavaScript
4949
url: quickstart-v2-javascript.md
50+
- text: Angular
51+
url: quickstart-v2-angular.md
5052
- linkListType: tutorial
5153
links:
5254
- text: JavaScript
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: Sign in users in Angular single-page apps - Azure
3+
titleSuffix: Microsoft identity platform
4+
description: Learn how an Angular app can call an API that requires access tokens using the Microsoft identity platform.
5+
services: active-directory
6+
author: jasonnutter
7+
manager: CelesteDG
8+
9+
ms.service: active-directory
10+
ms.subservice: develop
11+
ms.custom: aaddev, identityplatformtop40, scenarios:getting-started, languages:JavaScript
12+
ms.topic: quickstart
13+
ms.workload: identity
14+
ms.date: 03/18/2020
15+
ms.author: janutter
16+
17+
#Customer intent: As an app developer, I want to learn how to get access tokens by using the Microsoft identity platform endpoint so that my Angular app can sign in users of personal Microsoft accounts, and work and school accounts.
18+
---
19+
20+
# Quickstart: Sign in users and get an access token in an Angular SPA
21+
22+
> [!IMPORTANT]
23+
> This feature is currently in preview. Previews are made available to you on the condition that you agree to the [supplemental terms of use](https://azure.microsoft.com/support/legal/preview-supplemental-terms/). Some aspects of this feature may change prior to general availability (GA).
24+
25+
In this quickstart, you use a code sample to learn how an Angular single-page application (SPA) can sign in users who have personal Microsoft accounts, and work accounts and school accounts. An Angular SPA can also get an access token to call the Microsoft Graph API or any web API.
26+
27+
## Prerequisites
28+
29+
* Azure subscription - [create one for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F)
30+
* [Node.js](https://nodejs.org/en/download/)
31+
* [Visual Studio Code](https://code.visualstudio.com/download) to edit project files, or [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/) to run the project.
32+
33+
> [!div renderon="docs"]
34+
> ## Register and download the quickstart app
35+
> To start the quickstart app, use either of the following options:
36+
>
37+
> ### Option 1 (Express): Register and auto configure the app. Then download the code sample
38+
>
39+
> 1. Sign in to the [Azure portal](https://portal.azure.com) using either a work or school account, or a personal Microsoft account.
40+
> 1. If your account has access to more than one tenant, select the account at the top right, and then set your portal session to the Azure Active Directory (Azure AD) tenant you want to use.
41+
> 1. Open the new [Azure portal - App registrations](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade/quickStartType/JavascriptSpaQuickstartPage/sourceType/docs) pane.
42+
> 1. Enter a name for your application, and then select **Register**.
43+
> 1. Navigate to the quickstart pane and view the Angular quickstart. Follow the instructions to download and automatically configure your new application.
44+
>
45+
> ### Option 2 (Manual): Register and manually configure the application and code sample
46+
>
47+
> #### Step 1: Register the application
48+
>
49+
> 1. Sign in to the [Azure portal](https://portal.azure.com) using either a work or school account, or a personal Microsoft account.
50+
>
51+
> 1. If your account has access to more than one tenant, select your account at the top right, and set your portal session to the Azure AD tenant you want to use.
52+
> 1. Follow the instructions to [register a single-page application](https://docs.microsoft.com/azure/active-directory/develop/scenario-spa-app-registration) in the Azure portal.
53+
> 1. Add a new platform in the **Authentication blade** of your app registration and register the redirect URI: `http://localhost:4200/`
54+
> 1. This quickstart uses the [implicit grant flow](v2-oauth2-implicit-grant-flow.md). Select the **Implicit Grant** settings for **ID tokens** and **Access Tokens**. ID tokens and access tokens are required because this app signs in users and calls an API.
55+
56+
> [!div class="sxs-lookup" renderon="portal"]
57+
> #### Step 1: Configure the application in the Azure portal
58+
> For the code sample for this quickstart to work, you need to add a `redirectUri` as `http://localhost:4200/` and enable **Implicit grant**.
59+
> > [!div renderon="portal" id="makechanges" class="nextstepaction"]
60+
> > [Make these changes for me]()
61+
>
62+
> > [!div id="appconfigured" class="alert alert-info"]
63+
> > ![Already configured](media/quickstart-v2-javascript/green-check.png) Your application is configured with these attributes.
64+
65+
#### Step 2: Download the code sample
66+
>[!div renderon="docs"]
67+
>To run the project with a web server by using Node.js, clone https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-angular or [download](https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-angular/archive/master.zip) the core project files. Open the files using an editor such as Visual Studio Code.
68+
69+
> [!div renderon="portal" id="autoupdate" class="sxs-lookup" class="nextstepaction"]
70+
> [Download the code sample](https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-angular/archive/master.zip)
71+
72+
> [!div renderon="docs"]
73+
>#### Step 3: Configure the JavaScript app
74+
>
75+
> In the *src/app* folder, edit *app.module.ts* and set the `clientId` and `authority` values under `MsalModule.forRoot`.
76+
>
77+
>```javascript
78+
>MsalModule.forRoot({
79+
> auth: {
80+
> clientId: 'Enter_the_Application_Id_here', // This is your client ID
81+
> authority: 'https://login.microsoftonline.com/Enter_the_Tenant_Info_Here', // This is your tenant info
82+
> redirectUri: 'Enter_the_Redirect_Uri_Here' // This is your redirect URI
83+
> },
84+
> cache: {
85+
> cacheLocation: 'localStorage',
86+
> storeAuthStateInCookie: isIE, // set to true for IE 11
87+
> },
88+
>},
89+
> //... )
90+
>```
91+
92+
> [!div class="sxs-lookup" renderon="portal"]
93+
> > [!NOTE]
94+
> > Enter_the_Supported_Account_Info_Here
95+
96+
97+
> [!div renderon="docs"]
98+
>
99+
> Replace these values as such:
100+
>
101+
>|Value name|Description|
102+
>|---------|---------|
103+
>|Enter_the_Application_Id_Here|In the **overview** page of your application registration, this is your **application(client) ID** |
104+
>|Enter_the_Cloud_Instance_Id_Here|This is the instance of the Azure cloud. For the main or global Azure cloud, enter https://login.microsoftonline.com. For national clouds (for example, China), see [National clouds](https://docs.microsoft.com/azure/active-directory/develop/authentication-national-cloud).|
105+
>|Enter_the_Tenant_Info_Here| Set to one of the following options: 1) If your application supports *accounts in this organizational directory*, replace this value with the **Directory (Tenant) ID** or **Tenant name** (for example, *contoso.microsoft.com*). 2) If your application supports *accounts in any organizational directory*, replace this value with **organizations**. 3) If your application supports *accounts in any organizational directory and personal Microsoft accounts*, replace this value with **common**. 4) To restrict support to *personal Microsoft accounts only*, replace this value with **consumers**. |
106+
>|Enter_the_Redirect_Uri_Here|Replace with `http://localhost:4200`|
107+
>|cacheLocation | (Optional) Sets the browser storage for the auth state. The default is sessionStorage. |
108+
>|storeAuthStateInCookie | (Optional) The library that stores the authentication request state. This state is required to validate the authentication flows in the browser cookies. This cookie is set for the Internet Explorer and Edge browsers to accommodate those two browsers. For more details, see [known issues](https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/Known-issues->on-IE-and-Edge-Browser#issues). |
109+
> > [!TIP]
110+
> > To find the values of **Application (client) ID**, **Directory (tenant) ID**, and **Supported account types**, go to the app's **Overview** page in the Azure portal.
111+
112+
For more information about available configurable options, see [Initialize client applications](msal-js-initializing-client-applications.md).
113+
114+
>[!div class="sxs-lookup" renderon="portal"]
115+
>#### Step 3: Run the project
116+
117+
>[!div renderon="docs"]
118+
>#### Step 4: Run the project
119+
120+
* If you're using Node.js:
121+
122+
1. Start the server by running the following commands from the project directory:
123+
124+
```console
125+
npm install
126+
npm start
127+
```
128+
129+
1. Browse `http://localhost:4200/`.
130+
1. Select **Login**.
131+
1. Select **Profile** to call Microsoft Graph.
132+
133+
After the browser loads the application, select **Login**. The first time you sign in, you're prompted to provide your consent to allow the application to access your profile and sign you in. After you're signed in successfully, select **Profile**, and your user profile information will be displayed on the page.
134+
135+
## How the sample works
136+
137+
![How the sample app in this quickstart works](media/quickstart-v2-javascript/javascriptspa-intro.svg)
138+
139+
140+
## Next steps
141+
142+
> [!div class="nextstepaction"]
143+
> Go to the [Angular Tutorial](https://docs.microsoft.com/azure/active-directory/develop/tutorial-v2-angular) to learn how to sign in a user and acquire tokens.
144+
145+
Browse the [MSAL repo](https://github.com/AzureAD/microsoft-authentication-library-for-js) for documentation, FAQ, issues, and more.

articles/active-directory/develop/reference-v2-libraries.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The Microsoft identity platform endpoint works with two types of libraries:
4141
Libraries come in two support categories:
4242

4343
* **Microsoft-supported**: Microsoft provides fixes for these libraries and has done SDL due diligence on these libraries.
44-
* **Compatible**: Microsoft has tested these libraries in basic scenarios and has confirmed that they work with the Microsoft identity platform endpoint. Microsoft doesn't provide fixes for these libraries and hasn't done a review of these libraries. Issues and feature requests should be directed to the librarys open-source project.
44+
* **Compatible**: Microsoft has tested these libraries in basic scenarios and has confirmed that they work with the Microsoft identity platform endpoint. Microsoft doesn't provide fixes for these libraries and hasn't done a review of these libraries. Issues and feature requests should be directed to the library's open-source project.
4545

4646
For a list of libraries that work with the Microsoft identity platform endpoint, see the following sections.
4747

@@ -51,9 +51,8 @@ Use client authentication libraries to acquire a token for calling a protected w
5151

5252
| Platform | Library | Download | Source code | Sample | Reference | Conceptual doc | Roadmap |
5353
| --- | --- | --- | --- | --- | --- | --- | --- |
54-
| ![JavaScript](media/sample-v2-code/logo_js.png) | MSAL.js | [NPM](https://www.npmjs.com/package/msal) |[GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/README.md) | [Single-page app](https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-dotnet-webapi-v2) | [Reference](https://azuread.github.io/microsoft-authentication-library-for-js/docs/msal/) | [Conceptual docs](msal-overview.md)| [Roadmap](https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki#roadmap)
55-
|![Angular JS](media/sample-v2-code/logo_angular.png) | MSAL Angular JS | [NPM](https://www.npmjs.com/package/@azure/msal-angularjs) | [GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-angularjs/README.md) | | | |
56-
![Angular](media/sample-v2-code/logo_angular.png) | MSAL Angular (Preview) | [NPM](https://www.npmjs.com/package/@azure/msal-angular) |[GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/README.md) | | | |
54+
| ![JavaScript](media/sample-v2-code/logo_js.png) | MSAL.js | [NPM](https://www.npmjs.com/package/msal) |[GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/README.md) | [Single-page app](https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-dotnet-webapi-v2) | [Reference](https://azuread.github.io/microsoft-authentication-library-for-js/ref/msal-core/) | [Conceptual docs](msal-overview.md)| [Roadmap](https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki#roadmap)
55+
![Angular](media/sample-v2-code/logo_angular.png) | MSAL Angular | [NPM](https://www.npmjs.com/package/@azure/msal-angular) |[GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/README.md) | [Angular SPA](https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-angular) | [Reference](https://azuread.github.io/microsoft-authentication-library-for-js/ref/msal-angular/) | [Conceptual docs](msal-overview.md) | [Roadmap](https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki#roadmap)
5756
| ![.NET Framework](media/sample-v2-code/logo_NET.png) ![UWP](media/sample-v2-code/logo_windows.png) ![Xamarin](media/sample-v2-code/logo_xamarin.png) | MSAL.NET |[NuGet](https://www.nuget.org/packages/Microsoft.Identity.Client) |[GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet) | [Desktop app](guidedsetups/active-directory-mobileanddesktopapp-windowsdesktop-intro.md) | [MSAL.NET](https://docs.microsoft.com/dotnet/api/microsoft.identity.client?view=azure-dotnet-preview) |[Conceptual docs](msal-overview.md) | [Roadmap](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki#roadmap)
5857
| ![Python](media/sample-v2-code/logo_python.png) | MSAL Python | [PyPI](https://pypi.org/project/msal) | [GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-python) | [Samples](https://github.com/AzureAD/microsoft-authentication-library-for-python/tree/dev/sample) | [ReadTheDocs](https://msal-python.rtfd.io/) | [Wiki](https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki) | [Roadmap](https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki/Roadmap)
5958
| ![Java](media/sample-v2-code/logo_java.png) | MSAL Java | [Maven](https://mvnrepository.com/artifact/com.microsoft.azure/msal4j) | [GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-java) | [Samples](https://github.com/AzureAD/microsoft-authentication-library-for-java/tree/dev/src/samples) | [Reference](https://javadoc.io/doc/com.microsoft.azure/msal4j/latest/index.html) | [Wiki](https://github.com/AzureAD/microsoft-authentication-library-for-java/wiki) | [Roadmap](https://github.com/AzureAD/microsoft-authentication-library-for-java/wiki)
@@ -77,7 +76,7 @@ In term of supported operating systems vs languages, the mapping is the followin
7776
| | Windows | Linux | macOS | iOS | Android |
7877
|-------------|------------|------------|------------|------------|------------|
7978
| ![JavaScript](media/sample-v2-code/logo_js.png) | MSAL.js | MSAL.js | MSAL.js | MSAL.js | MSAL.js |
80-
| <img alt="C#" src="../../cognitive-services/speech-service/media/index/logo_csharp.svg" width="64px" height="64px" /> | ASP.NET, ASP.NET Core, MSAL.Net (.NET FW, Core, UWP)| ASP.NET Core, MSAL.Net (.NET Core) | ASP.NET Core, MSAL.Net (MacOS) | MSAL.Net (Xamarin.iOS) | MSAL.Net (Xamarin.Android)|
79+
| <img alt="C#" src="../../cognitive-services/speech-service/media/index/logo_csharp.svg" width="64px" height="64px" /> | ASP.NET, ASP.NET Core, MSAL.Net (.NET FW, Core, UWP)| ASP.NET Core, MSAL.Net (.NET Core) | ASP.NET Core, MSAL.Net (macOS) | MSAL.Net (Xamarin.iOS) | MSAL.Net (Xamarin.Android)|
8180
| Swift <br> Objective-C | | | [MSAL for iOS and macOS](msal-overview.md) | [MSAL for iOS and macOS](msal-overview.md) | |
8281
| ![Java](media/sample-v2-code/logo_java.png) Java | msal4j | msal4j | msal4j | | MSAL Android |
8382
| ![Python](media/sample-v2-code/logo_python.png) Python | MSAL Python | MSAL Python | MSAL Python |
@@ -98,7 +97,7 @@ See also [Scenarios by supported platforms and languages](authentication-flows-a
9897
| ![Ruby](media/sample-v2-code/logo_ruby.png) |[OmniAuth](https://github.com/omniauth/omniauth/wiki) |omniauth: 1.3.1<br />omniauth-oauth2: 1.4.0 |[OmniAuth](https://github.com/omniauth/omniauth)<br />[OmniAuth OAuth2](https://github.com/intridea/omniauth-oauth2) | |
9998
| iOS, macOS, & Android | [React Native App Auth](https://github.com/FormidableLabs/react-native-app-auth) | [Version 4.2.0](https://github.com/FormidableLabs/react-native-app-auth/releases/tag/v4.2.0) | [React Native App Auth](https://github.com/FormidableLabs/react-native-app-auth) | |
10099

101-
For any standards-compliant library, you can use the Microsoft identity platform endpoint. Its important to know where to go for support:
100+
For any standards-compliant library, you can use the Microsoft identity platform endpoint. It's important to know where to go for support:
102101

103102
* For issues and new feature requests in library code, contact the library owner.
104103
* For issues and new feature requests in the service-side protocol implementation, contact Microsoft.

0 commit comments

Comments
 (0)