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
|`App/utils/graphManager.js`| Handles calls to Microsoft Graph using Graph JS SDK. |
@@ -148,7 +148,7 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
148
148
149
149
> In the steps below, "ClientID" is the same as "Application ID" or "AppId".
150
150
151
-
1. Open the `App/appSettings.json` file.
151
+
1. Open the `App/appSettings.js` file.
152
152
1. Find the key `clientId` and replace the existing value with the application ID (clientId) of `msal-node-webapp` app copied from the Azure portal.
153
153
1. Find the key `tenantId` and replace the existing value with your Azure AD tenant ID.
154
154
1. Find the key `clientSecret` and replace the existing value with the key you saved during the creation of `msal-node-webapp` copied from the Azure portal.
@@ -210,19 +210,176 @@ Scopes can come in various forms so it pays off to be familiar with them. The fo
app.listen(SERVER_PORT, () =>console.log(`Msal Node Auth Code Sample app listening on port ${SERVER_PORT}!`));
214
263
```
215
264
216
-
Under the hood, the `getToken` middleware grabs resource endpoint and associated scope from [appSettings.json](./App/appSettings.json), and attempts to obtain an access token from cache silently and attaches it to session. If silent token acquisition fails for some reason (e.g. consent required), it makes an auth code request, which triggers the first leg of auth code flow.
265
+
Under the hood, the [getToken()](https://azure-samples.github.io/msal-express-wrapper/classes/authprovider.html#gettoken) middleware grabs resource endpoint and associated scope from [appSettings.js](./App/appSettings.js), and attempts to obtain an access token from cache silently and attaches it to session. If silent token acquisition fails for some reason (e.g. consent required), it makes an auth code request, which triggers the first leg of auth code flow.
// get an auth code url and initiate the first leg of auth code grant to get token
325
+
returnthis.getAuthCode(req, res, next, params);
326
+
} else {
327
+
console.log(error);
328
+
next(error);
329
+
}
330
+
}
331
+
}
332
+
};
220
333
```
221
334
222
-
In the second leg of auth code flow, the auth code from redirect response is used to request a new access token (and refresh token) via the `handleRedirect` middleware.
335
+
In the second leg of auth code flow, the auth code from redirect response is used to request a new access token (and refresh token) via the [handleRedirect](https://azure-samples.github.io/msal-express-wrapper/classes/authprovider.html#handleredirect) middleware.
Copy file name to clipboardExpand all lines: 3-Deployment/README.md
+119-1Lines changed: 119 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,7 +151,7 @@ Finally, you need to add a few environment variables to the App Service where yo
151
151
1. Add the following variables (name-value):
152
152
1.**KEY_VAULT_URI**: the name of the key vault you've created, e.g. `example-key-vault`
153
153
1.**SECRET_NAME**: the name of the certificate you specified when importing it to key vault, e.g. `ExampleSecret`
154
-
1.**NODE_ENV**: enter `production`
154
+
1.**NODE_ENV**: enter `production` (:information_source: this enables your application to set cookies to secure and trust App service proxy)
155
155
156
156
Wait for a few minutes for your changes on **App Service** to take effect. You should then be able to visit your published website and sign-in accordingly.
157
157
@@ -172,10 +172,128 @@ Were we successful in addressing your learning objective? Consider taking a mome
172
172
173
173
### Accessing Key Vault using Managed Identity
174
174
175
+
In [appSettings.js](./App/appSettings.js) file, we enter the parameters needed for accessing [Azure Key Vault](https://docs.microsoft.com/azure/key-vault/general/basic-concepts) to fetch the application's credentials:
Then in [app.js](./App/app.js), we instantiate an **authProvider** object asynchronously using the [buildAsync](https://azure-samples.github.io/msal-express-wrapper/classes/authprovider.html#buildasync) method of [AuthProvider](https://azure-samples.github.io/msal-express-wrapper/classes/authprovider.html). To do so, we need to start the express server asynchronously:
207
+
175
208
```javascript
209
+
constexpress=require('express');
210
+
constsession=require('express-session');
211
+
constmsalWrapper=require('msal-express-wrapper');
212
+
213
+
// async function to wait for key vault credentials before start
214
+
asyncfunctionmain() {
215
+
constapp=express();
216
+
217
+
/**
218
+
* Using express-session middleware. Be sure to familiarize yourself with available options
219
+
* and set them as desired. Visit: https://www.npmjs.com/package/express-session
app.listen(SERVER_PORT, () =>console.log(`Msal Node Auth Code Sample app listening on port ${SERVER_PORT}!`));
239
+
}
240
+
241
+
main();
176
242
```
177
243
244
+
Under the hood, the wrapper calls the **Azure Key Vault** to access credentials needed for the application to authenticate with Azure AD using the [KeyVaultManager](https://azure-samples.github.io/msal-express-wrapper/classes/keyvaultmanager.html) class. This class is leveraging the [@azure/identity](https://www.npmjs.com/package/@azure/identity) and [@azure/key-vault](https://www.npmjs.com/package/@azure/keyvault-secrets) packages:
0 commit comments