|
| 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 `UserAgentApplication`. |
| 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 | +1. 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 | +2. Make a request to the instance discovery endpoint |
| 17 | +3. Look at the **metadata** field from the response and find your authority domain in one of the `aliases` lists |
| 18 | +4. Provide the **entire** JSON object for each authority you intend to use as a member of an array in the `auth.instanceMetadata` property. |
| 19 | + |
| 20 | +The example shown below shows 5 such JSON objects in the array. If none of the aliases listed match your authority you do not need to include the corresponding object in the array. |
| 21 | + |
| 22 | +Example: |
| 23 | + |
| 24 | +```js |
| 25 | +const msalInstance = new msal.UserAgentApplication({ |
| 26 | + auth: { |
| 27 | + instanceMetadata: [ |
| 28 | + { |
| 29 | + "preferred_network":"login.microsoftonline.com", |
| 30 | + "preferred_cache":"login.windows.net", |
| 31 | + "aliases":["login.microsoftonline.com","login.windows.net","login.microsoft.com","sts.windows.net"] |
| 32 | + }, |
| 33 | + { |
| 34 | + "preferred_network":"login.partner.microsoftonline.cn", |
| 35 | + "preferred_cache":"login.partner.microsoftonline.cn", |
| 36 | + "aliases":["login.partner.microsoftonline.cn","login.chinacloudapi.cn"] |
| 37 | + }, |
| 38 | + { |
| 39 | + "preferred_network":"login.microsoftonline.de", |
| 40 | + "preferred_cache":"login.microsoftonline.de", |
| 41 | + "aliases":["login.microsoftonline.de"] |
| 42 | + }, |
| 43 | + { |
| 44 | + "preferred_network":"login.microsoftonline.us", |
| 45 | + "preferred_cache":"login.microsoftonline.us", |
| 46 | + "aliases":["login.microsoftonline.us","login.usgovcloudapi.net"] |
| 47 | + }, |
| 48 | + { |
| 49 | + "preferred_network":"login-us.microsoftonline.com", |
| 50 | + "preferred_cache":"login-us.microsoftonline.com", |
| 51 | + "aliases":["login-us.microsoftonline.com"] |
| 52 | + } |
| 53 | + ] |
| 54 | + } |
| 55 | +}); |
| 56 | +``` |
0 commit comments