|
1 | 1 | ---
|
2 | 2 | title: Overview
|
| 3 | +description: Overview of the Microsoft Authentication Libraries for JavaScript |
| 4 | +services: active-directory |
3 | 5 | author: Dickson-Mwendia
|
| 6 | +manager: CelesteDG |
| 7 | + |
| 8 | +ms.service: active-directory |
| 9 | +ms.subservice: develop |
| 10 | +ms.topic: reference |
| 11 | +ms.workload: identity |
| 12 | +ms.date: 01/10/2023 |
| 13 | +ms.author: dmwendia |
4 | 14 | ---
|
| 15 | +# Microsoft Authentication Library for JavaScript (MSAL.js) |
5 | 16 |
|
6 |
| -# Microsoft Authentication Library for Node (MSAL Node) |
| 17 | +The Microsoft Authentication Library for JavaScript enables both client-side and server-side JavaScript applications to authenticate users using [Azure Active Directory](/../../azure/active-directory/develop/v2-overview) (Azure AD) for work and school accounts, Microsoft personal accounts (MSA), and social identity providers like Facebook, Google, LinkedIn, Microsoft accounts, etc. through [Azure AD B2C](/../../azure/active-directory-b2c/active-directory-b2c-overview#identity-providers) service. It also enables your app to get tokens to access [Microsoft Cloud](https://www.microsoft.com/enterprise) services such as [Microsoft Graph](https://graph.microsoft.io). |
7 | 18 |
|
8 |
| -MSAL Node enables applications to authenticate users using [Azure AD](https://docs.microsoft.com/azure/active-directory/develop/v2-overview) work and school accounts, Microsoft personal accounts (MSA) and social identity providers like Facebook, Google, LinkedIn, and Microsoft accounts through [Azure AD B2C](https://docs.microsoft.com/azure/active-directory-b2c/active-directory-b2c-overview#identity-providers) service. It also enables your app to get tokens to access [Microsoft Cloud](https://www.microsoft.com/enterprise) services such as [Microsoft Graph](https://graph.microsoft.io). |
9 | 19 |
|
10 |
| -### Supported OAuth2.0 grant types |
| 20 | +## Core and wrapper libraries |
11 | 21 |
|
12 |
| -The current version supports the following ways of acquiring tokens: |
| 22 | +The [`lib`](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib) folder contains the source code for our libraries in active development. You will also find all the details about **installing the libraries** in their respective README.md files. |
13 | 23 |
|
14 |
| -#### Public Client: |
| 24 | +- **Microsoft Authentication Library for Node.js v1.x:** A [Node.js](https://nodejs.org/en/) library that enables authentication and token acquisition with the Microsoft Identity platform in JavaScript applications. Implements the following OAuth 2.0 protocols and is [OpenID-compliant](/../../azure/active-directory/develop/v2-protocols-oidc): |
| 25 | + - [Authorization Code Grant](https://oauth.net/2/grant-types/authorization-code/) with [PKCE](https://oauth.net/2/pkce/) |
| 26 | + - [Device Code Grant](https://oauth.net/2/grant-types/device-code/) |
| 27 | + - [Refresh Token Grant](https://oauth.net/2/grant-types/refresh-token/) |
| 28 | + - [Client Credential Grant](https://oauth.net/2/grant-types/client-credentials/) |
15 | 29 |
|
16 |
| -- [Authorization Code Grant](https://oauth.net/2/grant-types/authorization-code/) with [PKCE](https://oauth.net/2/pkce/) |
17 |
| -- [Device Code Grant](https://oauth.net/2/grant-types/device-code/) |
18 |
| -- [Refresh Token Grant](https://oauth.net/2/grant-types/refresh-token/) |
19 |
| -- [Silent Flow](https://docs.microsoft.com/azure/active-directory/develop/msal-acquire-cache-tokens#acquiring-tokens-silently-from-the-cache) |
20 |
| -- [Username and Password flow](https://docs.microsoft.com/azure/active-directory/develop/msal-authentication-flows#usernamepassword) |
| 30 | +- **Microsoft Authentication Library for JavaScript v2.x**: A browser-based, framework-agnostic browser library that enables authentication and token acquisition with the Microsoft Identity platform in JavaScript applications. Implements the OAuth 2.0 [Authorization Code Flow with PKCE](/../../azure/active-directory/develop/v2-oauth2-auth-code-flow), and is [OpenID-compliant](/../../azure/active-directory/develop/v2-protocols-oidc). |
21 | 31 |
|
22 |
| -#### Confidential Client: |
| 32 | +- **Microsoft Authentication Library for React v1.x**: A wrapper of the msal-browser 2.x library for apps using React. |
23 | 33 |
|
24 |
| -- [Authorization Code Grant](https://oauth.net/2/grant-types/authorization-code/) with a client credential |
25 |
| -- [Refresh Token Grant](https://oauth.net/2/grant-types/refresh-token/) |
26 |
| -- [Silent Flow](https://docs.microsoft.com/azure/active-directory/develop/msal-acquire-cache-tokens#acquiring-tokens-silently-from-the-cache) |
27 |
| -- [Client Credential Grant](https://oauth.net/2/grant-types/client-credentials/) |
28 |
| -- [On-behalf-of flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow) |
29 |
| -- [Username and Password flow](https://docs.microsoft.com/azure/active-directory/develop/msal-authentication-flows#usernamepassword) |
| 34 | +- **Microsoft Authentication Library for Angular v2.x**: A wrapper of the msal-browser 2.x library for apps using Angular framework. |
30 | 35 |
|
31 |
| -More details on different grant types supported by Microsoft authentication libraries in general can be found in [MSAL authentication flows](https://docs.microsoft.com/azure/active-directory/develop/msal-authentication-flows). |
| 36 | +- **Microsoft Authentication Library for JavaScript v1.x**: A browser-based, framework-agnostic core library that enables authentication and token acquisition with the Microsoft Identity platform in JavaScript applications. Implements the OAuth 2.0 [Implicit Grant Flow](/../../azure/active-directory/develop/v2-oauth2-implicit-grant-flow), and is [OpenID-compliant](/../../azure/active-directory/develop/v2-protocols-oidc). |
32 | 37 |
|
33 |
| -### Supported application scenarios |
| 38 | +- [Microsoft Authentication Library for Angular](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/msal-angular-v1/lib/msal-angular): A wrapper of the core 1.x library for apps using Angular framework. |
34 | 39 |
|
35 |
| -MSAL Node supports the following application scenarios: |
| 40 | +## Package structure |
36 | 41 |
|
37 |
| -- Desktop app that calls web APIs |
38 |
| -- Web app that calls web APIs |
39 |
| -- Web APIs that call web APIs |
40 |
| -- Daemon apps |
| 42 | +There are a number of different packages meant for different platforms. You can see the relationship between packages and different authentication flows they implement in the package structure below. |
41 | 43 |
|
42 |
| -Learn more about the application scenarios that MSAL Node supports in the [scenarios and authentication flows article](https://docs.microsoft.com/azure/active-directory/develop/authentication-flows-app-scenarios). |
43 |
| - |
44 |
| -## Prerequisites |
45 |
| - |
46 |
| -Before using `@azure/msal-node` you will need to register your app in the Azure portal. Follow thee steps in [App registration](https://docs.microsoft.com/graph/auth-register-app-v2) to register your application in the Azure portal. |
47 |
| - |
48 |
| -## Installation |
49 |
| - |
50 |
| -To install MSAL Node using npm, use the following commands: |
51 |
| - |
52 |
| -```javascript |
53 |
| -npm install @azure/msal-node |
54 |
| -``` |
55 |
| - |
56 |
| -## Usage |
57 |
| - |
58 |
| -### MSAL basics |
59 |
| -- [Understand difference in between Public Client and Confidential Clients](https://docs.microsoft.com/azure/active-directory/develop/msal-client-applications) |
60 |
| -- [Initialize a Public Client Application](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/initialize-public-client-application.md) |
61 |
| -- [Initialize a Confidential Client Application](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/initialize-confidential-client-application.md) |
62 |
| -- [Configuration](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/configuration.md) |
63 |
| -- [Request](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-common/docs/request.md) |
64 |
| -- [Response](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-common/docs/Response.md) |
| 44 | + |
65 | 45 |
|
66 | 46 | ## Samples
|
67 | 47 |
|
68 |
| -There are multiple [samples](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples) on GitHub that use MSAL Node to acquire tokens. Developers can use these sample apps for learning and testing purposes. |
69 |
| - |
70 |
| -- [auth-code](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/auth-code): Express app using OAuth2.0 authorization code flow. |
71 |
| -- [auth-code-pkce](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/auth-code-pkce): Express app using OAuth2.0 authorization code flow with PKCE. |
72 |
| -- [device-code](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/device-code): Command line app using OAuth 2.0 device code flow. |
73 |
| -- [refresh-token](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/refresh-token): Command line app using OAuth 2.0 refresh flow. |
74 |
| -- [silent-flow](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/silent-flow): Express app using OAuth2.0 authorization code flow to acquire a token and store in the token cache, and silent flow to use tokens in the token cache. |
75 |
| -- [client-credentials](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/client-credentials): Daemon app using OAuth 2.0 client credential grant to acquire a token. |
76 |
| -- [on-behalf-of](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/on-behalf-of): Web application using OAuth 2.0 auth code flow to acquire a token for a web API. The web API validates the token, and calls Microsoft Graph on behalf of the user who authenticated in the web application. |
77 |
| -- [username-password](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/username-password): Web application using OAuth 2.0 resource owner password credentials (ROPC) flow to acquire a token for a web API. |
78 |
| -- [ElectronTestApp](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/ElectronTestApp): Electron desktop application using OAuth 2.0 auth code with PKCE flow to acquire a token for a web API such as Microsoft Graph. |
79 |
| -- [ExpressTestApp](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/ExpressTestApp): Express.js MVC web application using OAuth 2.0 auth code with PKCE flow to acquire a token for a web API such as Microsoft Graph. |
80 |
| -- [Hybrid SPA sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-browser-samples/HybridSample): Sample demonstrating how to use `enableSpaAuthorizationCode` to perform SSO for applications that leverage server-side and client-side authentication using MSAL Browser and MSAL Node. |
81 |
| - |
82 |
| -B2C samples: |
83 |
| - |
84 |
| -- [b2c-user-flows](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples/b2c-user-flows): Express app using OAuth2.0 authorization code flow. |
85 |
| -- [ms-identity-b2c-javascript-nodejs-management](https://github.com/Azure-Samples/ms-identity-b2c-javascript-nodejs-management/tree/main/Chapter2): Command line app using OAuth 2.0 client credentials flow for performing user management operations on an Azure AD / Azure AD B2C tenant |
86 |
| - |
87 |
| -Others: |
88 |
| - |
89 |
| -- [msal-node-extensions](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/extensions/samples/msal-node-extensions): Uses authorization code flow to acquire tokens and the [msal-extensions](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/extensions/) library to write the MSAL in-memory token cache to disk. |
90 |
| - |
91 |
| -## Build and test |
92 |
| - |
93 |
| -- If you don't have [lerna](https://github.com/lerna/lerna) installed, run `npm install -g lerna` |
94 |
| -- Run `lerna bootstrap` from anywhere within `microsoft-authentication-library-for-js.git`. |
95 |
| -- Navigate to `microsoft-authentication-library-for-js/lib/msal-common` and run `npm run build` |
96 |
| -- Navigate to `microsoft-authentication-library-for-js/lib/msal-node` and run `npm run build` |
97 |
| - |
98 |
| -```javascript |
99 |
| -// to link msal-node and msal-common packages |
100 |
| -lerna bootstrap |
101 |
| - |
102 |
| -// Change to the msal-node package directory |
103 |
| -cd lib/msal-common/ |
104 |
| - |
105 |
| -// To run build only for node package |
106 |
| -npm run build |
107 |
| - |
108 |
| -// Change to the msal-node package directory |
109 |
| -cd lib/msal-node/ |
| 48 | +The [`code samples`](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples) demonstrate usage of the Microsoft authentication libraries for JavaScript with the identity platform. Each code sample includes a `README.md` file describing how to build the project (if applicable) and run the sample application. |
110 | 49 |
|
111 |
| -// To run build only for node package |
112 |
| -npm run build |
113 |
| -``` |
| 50 | +For a complete list of samples targeting JavaScript and other languages, frameworks, and platforms, please refer to the [Microsoft identity platform code samples](/../../azure/active-directory/develop/sample-v2-code). |
114 | 51 |
|
115 |
| -### Local development |
116 | 52 |
|
117 |
| -Below is a list of commands you will probably find useful: |
| 53 | +## Package versioning |
118 | 54 |
|
119 |
| -#### `npm run build:modules:watch` |
120 |
| -Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab. The library will be rebuilt if you make edits. |
| 55 | +All of our libraries follow [semantic versioning](https://semver.org). We recommend using the latest version of each library to ensure you have the latest security patches and bug fixes. |
121 | 56 |
|
122 |
| -#### `npm run build` |
123 |
| -Bundles the package to the `dist` folder. |
124 |
| -The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module). |
| 57 | +## Community help and support |
125 | 58 |
|
126 |
| -#### `lerna bootstrap` |
127 |
| -If you are running the project in development/watch mode, or have made changes in `msal-common` and need them reflecting across the project, please run `lerna bootstrap` to link all the symbols. Please note that `npm install` will unlink all the code, hence it is advised to run `lerna bootstrap` post installation. |
| 59 | +- [FAQs](https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/FAQs) for access to our frequently asked questions. |
128 | 60 |
|
129 |
| -#### `npm run lint` |
130 |
| -Runs eslint with Prettier |
| 61 | +- [Stack Overflow](http://stackoverflow.com/questions/tagged/msal) using "msal" and "msal.js" tag. |
131 | 62 |
|
132 |
| -#### `npm test`, `npm run test:coverage`, `npm run test:watch` |
133 |
| -Runs the test watcher (Jest) in an interactive mode. |
134 |
| -By default, runs tests related to files changed since the last commit. |
135 |
| -Generate code coverage by adding the flag --coverage. No additional setup needed. Jest can collect code coverage information from entire projects, including untested files. |
136 | 63 |
|
137 |
| -## Reporting security issues |
| 64 | +## Security reporting |
138 | 65 |
|
139 |
| -If you find a security issue with our libraries or services please report it to [[email protected]](mailto:[email protected]) with as much detail as possible. Your submission may be eligible for a bounty through the [Microsoft Bounty ](https://aka.ms/bugbounty) program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting [this page](https://technet.microsoft.com/security/dd252948) and subscribing to Security Advisory Alerts. |
| 66 | +If you find a security issue with our libraries or services [please report it to the Microsoft Security Response Center (MSRC)](https://aka.ms/report-security-issue) with as much detail as possible. Your submission may be eligible for a bounty through the [Microsoft Bounty](https://aka.ms/bugbounty) program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. If you'd like to get notifications of when security incidents occur, [subscribe to security advisory alerts](https://msrc-blog.microsoft.com/2022/08/09/security-update-guide-notification-system-news-create-your-profile-now/). |
0 commit comments