Skip to content

Commit 4cb10f0

Browse files
authored
Merge branch 'dev' into extensions-1
2 parents 7f539ae + 0f352a0 commit 4cb10f0

File tree

469 files changed

+5356
-2188
lines changed

Some content is hidden

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

469 files changed

+5356
-2188
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,4 @@ lib/msal-core/lib-es6
266266
*.tgz
267267
*.zip
268268
samples/**/test/screenshots
269+
samples/**/data/cache.json

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ The Microsoft Authentication Library for JavaScript enables client-side JavaScri
88

99
The [`lib`](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib) folder contains the source code for all of our libraries. You will also find all the details about **installing the libraries**, in their respective README.md.
1010

11+
- [Microsoft Authentication Library for Node.js v1.x (Alpha)](lib/msal-node/): 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](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-protocols-oidc):
12+
- [Authorization Code Grant](https://oauth.net/2/grant-types/authorization-code/) with [PKCE](https://oauth.net/2/pkce/)
13+
- [Device Code Grant](https://oauth.net/2/grant-types/device-code/)
14+
- [Refresh Token Grant](https://oauth.net/2/grant-types/refresh-token/)
15+
- [Client Credential Grant](https://oauth.net/2/grant-types/client-credentials/) (Coming soon)
16+
1117
- [Microsoft Authentication Library for JavaScript v2.x (Preview)](lib/msal-browser/): 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](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow), and is [OpenID-compliant](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-protocols-oidc).
1218

1319
- [Microsoft Authentication Library for JavaScript v1.x](lib/msal-core/): 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](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow), and is [OpenID-compliant](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-protocols-oidc).

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"packages": [
1717
"lib/*",
18-
"samples/*"
18+
"samples/**/*"
1919
],
2020
"version": "independent",
2121
"concurrency": 2

lib/msal-browser/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ See [here](https://github.com/AzureAD/microsoft-authentication-library-for-js/bl
4444

4545
| Date | Release | Announcement | Main features |
4646
| ------| ------- | ---------| --------- |
47-
| July 6th, 2020 (Tentative) | @azure/msal-browser v2.0.0 | No release notes yet | Full version of the `@azure/msal-browser` package; relies on `@azure/msal-common` v1.0.0 |
47+
| July 13th, 2020 (Tentative) | @azure/msal-browser v2.0.0 | No release notes yet | Full version of the `@azure/msal-browser` package; relies on `@azure/msal-common` v1.0.0 |
4848
| May 11, 2020 | @azure/msal-browser v2.0.0-beta | No release notes yet | Beta version of the `@azure/msal-browser` package; relies on `@azure/msal-common` v1.0.0-beta |
4949
| January 17, 2020 | @azure/msal-browser v2.0.0-alpha | No release notes yet | Alpha version of the `@azure/msal-browser` package with authorization code flow for SPAs working in dev; relies on msal-common v1.0.0-alpha |
5050

@@ -74,17 +74,19 @@ If you have MSAL v1.x currently running in your application, you can follow the
7474
2. [Logging in a User](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/login-user.md)
7575
3. [Acquiring and Using an Access Token](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/acquire-token.md)
7676
4. [Managing Token Lifetimes](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/token-lifetimes.md)
77-
5. [Logging Out a User](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/logout.md)
77+
5. [Managing Accounts](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-common/docs/Accounts.md)
78+
6. [Logging Out a User](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/logout.md)
7879

7980
### Advanced Topics
8081

8182
- [Configuration Options](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/configuration.md)
8283
- [Request and Response Details](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/request-response-object.md)
8384
- [Cache Storage](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/caching.md)
85+
- [Performance Enhancements](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/performance.md)
8486

8587
## Samples
8688

87-
The [`VanillaJSTestApp2.0` folder](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples) contains sample applications for our libraries. You can run any sample by changing the `authConfig.js` file in the respective folder to match your app registration and running the `npm` command `npm start -- -s <sample-name> -p <port>`.
89+
The [`VanillaJSTestApp2.0` folder](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples) contains sample applications for our libraries. You can run any sample by changing the `authConfig.js` file in the respective folder to match your app registration and running the `npm` command `npm start -- -s <sample-name> -p <port>`.
8890

8991
Here is a complete list of samples for the MSAL.js 2.x library:
9092

@@ -142,7 +144,7 @@ MSAL.js 1.x implemented the [Implicit Grant Flow](https://docs.microsoft.com/azu
142144

143145
Our goal is that the library abstracts enough of the protocol away so that you can get plug and play authentication, but it is important to know and understand the implicit flow from a security perspective. The MSAL 1.x client for single-page applications runs in the context of a web browser which cannot manage client secrets securely. It uses the implicit flow, which optimized for single page apps and has one less hop between client and server so tokens are returned directly to the browser. These aspects make it naturally less secure. These security concerns are mitigated per standard practices such as- use of short lived tokens (and so no refresh tokens are returned), the library requiring a registered redirect URI for the app, library matching the request and response with a unique nonce and state parameter. You can read more about the [disadvantages of the implicit flow here](https://tools.ietf.org/html/draft-ietf-oauth-browser-based-apps-04#section-9.8.6).
144146

145-
The MSAL library will now support the Authorization Code Flow with PKCE for Browser-Based Applications without a backend web server.
147+
The MSAL library will now support the Authorization Code Flow with PKCE for Browser-Based Applications without a backend web server.
146148
We plan to continue support for the implicit flow in the `msal-core` library.
147149

148150
You can learn further details about `@azure/msal-browser` functionality documented in our [docs folder](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-browser/docs) and find complete [code samples](#samples).

lib/msal-browser/changelog.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
1+
# 2.0.0-beta.4
2+
## Breaking Changes
3+
* Updated all APIs to send `openid` and `profile` by default in all requests (#1868)
4+
5+
## Features and Fixes
6+
* add interface for PublicClientApplication (#1870)
7+
* Update `monitorIframeForHash` to be purely time-based (#1873)
8+
* Instantiate Logger instance for PublicClientApplication (#1882)
9+
* Fix an issue with encoding in cookies and state values (#1852)
10+
* Fix issue where cache isn't being cleaned correctly (#1856)
11+
* Fix issue where expiration isn't calculated correctly (#1860)
12+
* Fix an issue where the crypto APIs were not truly random (#1872)
13+
* Remove all non-application specific initialization from PublicClientApplication constructor (#1885, #1886)
14+
* Added support for IE11 (#1883, #1884)
15+
* Added support for redirection to pages with custom hashes or query params (#1862)
16+
* Remove deprecated `handleRedirectCallback()` API (#1863)
17+
* Remove function typings for `redirectUri` and `postLogoutRedirectUri` (#1861).
18+
* Add support for Instance Discovery, combine all authority classes into a single generic class (#1811)
19+
120
# 2.0.0-beta.3
2-
* add `setKnownAuthorities` to constructor call for B2C Authority scenarios (#1646)
21+
## Breaking Changes
322
* `@azure/msal-browser` now follows a unified cache schema similar to other MSAL libraries (#1624, #1655, #1680, #1711, #1762, #1771)
423
* Updated browser library to follow common format for request, response, and client configurations (#1682, #1711, #1762, #1770, #1771, #1793)
524
* Account interface updated to AccountInfo.ts (#1789)
25+
26+
## Features and Fixes
27+
* add `setKnownAuthorities` to constructor call for B2C Authority scenarios (#1646)
628
* Library state is now sent as a encoded JSON object (#1790)
729
* Added a request object for logout APIs, made logout async (#1802)
830

lib/msal-browser/docs/acquire-token.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ msalInstance.acquireTokenSilent(request).then(tokenResponse => {
3939
return myMSALObj.acquireTokenPopup(request);
4040
}
4141
}).catch(error => {
42-
console.log(error);
42+
handleError(error);
4343
});
4444
```
4545

lib/msal-browser/docs/configuration.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const msalConfig = {
1414
clientId: "enter_client_id_here",
1515
authority: "https://login.microsoftonline.com/common",
1616
knownAuthorities: [],
17+
cloudDiscoveryMetadata: "",
1718
redirectUri: "enter_redirect_uri_here",
1819
postLogoutRedirectUri: "enter_postlogout_uri_here",
1920
navigateToLoginRequestUrl: true
@@ -62,6 +63,7 @@ const msalInstance = new PublicClientApplication(msalConfig);
6263
| `clientId` | App ID of your application. Can be found in your [portal registration](../README#prerequisites). | UUID/GUID | None. This parameter is required in order for MSAL to perform any actions. |
6364
| `authority` | URI of the tenant to authenticate and authorize with. Usually takes the form of `https://{uri}/{tenantid}`. | String in URI format with tenant - `https://{uri}/{tenantid}` | `https://login.microsoftonline.com/common` |
6465
| `knownAuthorities` | An array of URIs that are known to be valid. Used in B2C scenarios. | Array of strings in URI format | Empty array `[]` |
66+
| `cloudDiscoveryMetadata` | A string containing the cloud discovery response. Used in AAD scenarios. See performance.md for more info | string | Empty string `""` |
6567
| `redirectUri` | URI where the authorization code response is sent back to. Whatever location is specified here must have the MSAL library available to handle the response. | String in URI format | Login request page (`window.location.href` of page which made auth request) |
6668
| `postLogoutRedirectUri` | URI that is redirected to after a logout() call is made. | String in URI format | Login request page (`window.location.href` of page which made auth request) |
6769
| `navigateToLoginRequestUrl` | If `true`, will navigate back to the original request location before processing the authorization code response. If the `redirectUri` is the same as the original request location, this flag should be set to false. | boolean | `true` |

lib/msal-browser/docs/performance.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Performance
2+
3+
This document will outline techniques your application can use to improve the performance of acquire tokens using MSAL.js.
4+
5+
## Bypass cloud instance discovery resolution
6+
7+
By default, during the process of retrieving a token, MSAL.js will make a network request to retrieve metadata associated with the various Azure clouds. If you would like to skip this network request, you can provide the required metadata in the configuration of `PublicClientApplication`.
8+
9+
**Important:** It is your application's responsibility to ensure it is using correct, up-to-date cloud instance metadata. Failure to do so may result in your application not working correctly.
10+
11+
**Note:** If you are using B2C or ADFS authorities this document is not applicable. You will need to provide your authority domains to the `auth.knownAuthorities` property instead.
12+
13+
Instructions (AAD Scenarios):
14+
15+
Instance Discovery Endpoint: `https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=https://login.microsoftonline.com/common/oauth2/v2.0/authorize`
16+
17+
1. Make a request to the instance discovery endpoint above
18+
2. Provide the **entire** JSON response to the `auth.cloudDiscoveryMetadata` property.
19+
20+
**Note** If none of the aliases listed in the response match your authority you should pass your authority domain in `auth.knownAuthorities` instead.
21+
22+
Example:
23+
24+
```js
25+
const msalInstance = new msal.PublicClientApplication({
26+
auth: {
27+
cloudDiscoveryMetadata: '{"tenant_discovery_endpoint":"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration","api-version":"1.1","metadata":[{"preferred_network":"login.microsoftonline.com","preferred_cache":"login.windows.net","aliases":["login.microsoftonline.com","login.windows.net","login.microsoft.com","sts.windows.net"]},{"preferred_network":"login.partner.microsoftonline.cn","preferred_cache":"login.partner.microsoftonline.cn","aliases":["login.partner.microsoftonline.cn","login.chinacloudapi.cn"]},{"preferred_network":"login.microsoftonline.de","preferred_cache":"login.microsoftonline.de","aliases":["login.microsoftonline.de"]},{"preferred_network":"login.microsoftonline.us","preferred_cache":"login.microsoftonline.us","aliases":["login.microsoftonline.us","login.usgovcloudapi.net"]},{"preferred_network":"login-us.microsoftonline.com","preferred_cache":"login-us.microsoftonline.com","aliases":["login-us.microsoftonline.com"]}]}'
28+
}
29+
});
30+
```

lib/msal-browser/docs/request-response-object.md

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ All descriptions of silent request options can be found above except for:
174174
When you login a user, you can pass in scopes that the user can pre-consent to on login. However, this is not required. Please note that consenting to scopes on login, does not return an access_token for these scopes, but gives you the opportunity to obtain a token silently with these scopes passed in, with no further interaction from the user.
175175

176176
In our examples, we use the MS Graph scopes `user.read` and `mail.read`, so your scopes may look a little different.
177+
MSAL.js v2 no longer supports translation of `clientId` to `openid` and `profile` when provided in the scope list. If you need an idToken please pass `openid` and `profile`
177178

178179
It is best practice to only request scopes you need when you need them, a concept called dynamic consent. While this can create more interactive consent for users in your application, it also reduces drop-off from users that may be uneasy granting a large list of permissions for features they are not yet using.
179180

lib/msal-browser/docs/token-lifetimes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const tokenResponse = await msalInstance.acquireTokenSilent(silentRequest).catch
5353
if (error instanceof InteractionRequiredAuthError) {
5454
// fallback to interaction when silent call fails
5555
return await myMSALObj.acquireTokenPopup(request).catch(error => {
56-
console.log(error);
56+
handleError(error);
5757
});
5858
}
5959
});

lib/msal-browser/docs/v1-migration.md

+33-21
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,47 @@ Most APIs from MSAL 1.x have been carried forward to MSAL 2.x without change. So
3939
- `urlContainsHash`
4040
- `getCurrentConfiguration`
4141
- `getLoginInProgress`
42-
- `getAllAccounts`
42+
- `getAccount`
4343
- `getAccountState`
4444
- `isCallback`
4545

46-
In MSAL 2.x, handling the response from the hash is an asynchronous operation, as MSAL will perform a token exchange as soon as it parses the authorization code from the response. Because of this, when performing redirect calls, MSAL provides the `handleRedirectPromise` function which will return a promise that resolves when the redirect has been fully handled by MSAL.
46+
In MSAL 2.x, handling the response from the hash is an asynchronous operation, as MSAL will perform a token exchange as soon as it parses the authorization code from the response. Because of this, when performing redirect calls, MSAL provides the `handleRedirectPromise` function which will return a promise that resolves when the redirect has been fully handled by MSAL. When using a redirect method, the page used as the `redirectUri` must implement `handleRedirectPromise` to ensure the response is handled and tokens are cached when returning from the redirect.
4747

4848
```javascript
4949
const myMSALObj = new msal.PublicClientApplication(msalConfig);
5050

5151
// Register Callbacks for Redirect flow
5252
myMSALObj.handleRedirectPromise().then((tokenResponse) => {
53-
const accountObj = tokenResponse ? tokenResponse.account : myMSALObj.getAccount();
54-
if (accountObj) {
55-
// Account object was retrieved, continue with app progress
56-
console.log('id_token acquired at: ' + new Date().toString());
57-
} else if (tokenResponse && tokenResponse.tokenType === "Bearer") {
58-
// No account object available, but access token was retrieved
59-
console.log('access_token acquired at: ' + new Date().toString());
60-
} else if (tokenResponse === null) {
61-
// tokenResponse was null, attempt sign in or enter unauthenticated state for app
62-
signIn();
53+
let accountObj = null;
54+
if (tokenResponse !== null) {
55+
accountObj = tokenResponse.account;
56+
const id_token = tokenResponse.idToken;
57+
const access_token = tokenResponse.accessToken;
6358
} else {
64-
console.log("tokenResponse was not null but did not have any tokens: " + tokenResponse);
59+
const currentAccounts = myMSALObj.getAllAccounts();
60+
if (currentAccounts === null) {
61+
// No user signed in
62+
return;
63+
} else if (currentAccounts.length > 1) {
64+
// More than one user signed in, find desired user with getAccountByUsername(username)
65+
} else {
66+
accountObj = currentAccounts[0];
67+
}
6568
}
69+
70+
const username = accountObj.username;
71+
6672
}).catch((error) => {
67-
console.log(error);
73+
handleError(error);
6874
});
6975

70-
async function signIn() {
76+
function signIn() {
7177
myMSALObj.loginRedirect(loginRequest);
7278
}
7379

7480
async function getTokenRedirect(request) {
7581
return await myMSALObj.acquireTokenSilent(request).catch(error => {
76-
console.log("silent token acquisition fails. acquiring token using redirect");
82+
this.logger.info("silent token acquisition fails. acquiring token using redirect");
7783
// fallback to interaction when silent call fails
7884
return myMSALObj.acquireTokenRedirect(request)
7985
});
@@ -89,20 +95,26 @@ async function signIn(method) {
8995
try {
9096
const loginResponse = await myMSALObj.loginPopup(loginRequest);
9197
} catch (err) {
92-
console.log(error);
98+
handleError(error);
9399
}
94100

95-
if (myMSALObj.getAccount()) {
96-
showWelcomeMessage(myMSALObj.getAccount());
101+
const currentAccounts = myMSALObj.getAllAccounts();
102+
if (currentAccounts === null) {
103+
// No user signed in
104+
return;
105+
} else if (currentAccounts.length > 1) {
106+
// More than one user signed in, find desired user with getAccountByUsername(username)
107+
} else {
108+
accountObj = currentAccounts[0];
97109
}
98110
}
99111

100112
async function getTokenPopup(request) {
101113
return await myMSALObj.acquireTokenSilent(request).catch(async (error) => {
102-
console.log("silent token acquisition fails. acquiring token using popup");
114+
this.logger.info("silent token acquisition fails. acquiring token using popup");
103115
// fallback to interaction when silent call fails
104116
return await myMSALObj.acquireTokenPopup(request).catch(error => {
105-
console.log(error);
117+
handleError(error);
106118
});
107119
});
108120
}

lib/msal-browser/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)