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
@@ -17,38 +17,47 @@ In this quickstart, you incorporate Azure Cache for Redis into a Node.js app to
17
17
## Prerequisites
18
18
19
19
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
20
-
- Node.js installed, if you haven't done so already. See [Install Node.js on Windows](../../windows/dev-environment/javascript/nodejs-on-windows) for instructions on how to install Node and NPM on a Windows machine.
20
+
- Node.js installed, if you haven't done so already. See [Install Node.js on Windows](/windows/dev-environment/javascript/nodejs-on-windows) for instructions on how to install Node and Node Package Manager (NPM) on a Windows computer.
The [node-redis](https://github.com/redis/node-redis) library is the primary Node.js client for Redis. You can install the client with [npm](https://docs.npmjs.com/about-npm) by using the following command:
## [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
35
+
36
+
### Enable Microsoft Entra ID and add a User or Service Principal
37
+
38
+
[!INCLUDE cache-entra-access]
34
39
35
-
## Enable Microsoft EntraID and add a User or Service Principal
36
-
<--Fran, we probably need an include file on enabling EntraID-->
37
-
Blah blah blah, do the steps listed [here](cache-azure-active-directory-for-authentication)
40
+
### Install the JavaScript Azure Identity client library
38
41
39
-
## Install the JavaScript Azure Identity client library
40
-
The [Microsoft Authentication Library (MSAL)](../../entra/identity-platform/msal-overview) allows you to acquire security tokens from Microsoft identity to authenticate users. There's a [Javascript Azure identity client library](../../javascript/api/overview/azure/identity-readme) available that uses MSAL to provide token authentication support. Install this library using `npm`:
42
+
The [Microsoft Authentication Library (MSAL)](/entra/identity-platform/msal-overview) allows you to acquire security tokens from Microsoft identity to authenticate users. There's a [JavaScript Azure identity client library](/javascript/api/overview/azure/identity-readme) available that uses MSAL to provide token authentication support. Install this library using `npm`:
41
43
42
44
```bash
43
45
npm install @azure/identity
44
46
```
45
47
46
-
## Create a new Node.js app
48
+
### Create a new Node.js app using Microsoft Entra ID
49
+
50
+
1.Add environment variables for your **Host name** and **Service Principal ID**, which is the object ID your Microsoft Entra ID service principal or user. In the Azure portal, this is shown as the _Username_.
47
51
48
-
1. Create a new script file named *redistest.js*.
52
+
```cmd
53
+
set AZURE_CACHE_FOR_REDIS_HOST_NAME=contosoCache
54
+
set REDIS_SERVICE_PRINCIPAL_ID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
55
+
```
56
+
57
+
1. Create a new script file named _redistest.js_.
49
58
1. Add the following example JavaScript to the file.
@@ -130,6 +139,115 @@ This code shows you how to connect to an Azure Cache for Redis instance using th
130
139
Done
131
140
```
132
141
142
+
## Create a sample JavaScript app with reauthentication
143
+
144
+
Microsoft Entra ID access tokens have a limited lifespan, [averaging 75 minutes](../../entra/identity-platform/configurable-token-lifetimes#token-lifetime-policies-for-access-saml-and-id-tokens). In order to maintain a connection to your cache, you need to refresh the token. This example demonstrates how to do this using JavaScript.
145
+
146
+
1. Create a new script file named _redistestreauth.js_.
147
+
1. Add the following example JavaScript to the file.
>For additional examples of using Microsoft Entra ID to authenticate to Redis using the node-redis library, please see [this GitHub repo](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureCacheForRedis/node-redis.md)
@@ -149,7 +267,7 @@ set AZURE_CACHE_FOR_REDIS_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
149
267
150
268
## Create a new Node.js app
151
269
152
-
1. Create a new script file named *redistest.js*.
270
+
1. Create a new script file named _redistest.js_.
153
271
1. Add the following example JavaScript to the file.
154
272
155
273
```javascript
@@ -232,6 +350,7 @@ set AZURE_CACHE_FOR_REDIS_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
232
350
233
351
Done
234
352
```
353
+
235
354
---
236
355
237
356
## Clean up resources
@@ -244,7 +363,7 @@ If you continue to the next tutorial, can keep the resources created in this qui
244
363
245
364
1. Sign in to the [Azure portal](https://portal.azure.com) and select**Resource groups**.
246
365
247
-
1. In the **Filter by name** text box, enter the name of your resource group. The instructions forthis article used a resource group named *TestResources*. On your resource groupin the result list, select**...**then**Delete resource group**.
366
+
1. In the **Filter by name** text box, enter the name of your resource group. The instructions forthis article used a resource group named _TestResources_. On your resource groupin the result list, select**...**then**Delete resource group**.
@@ -256,9 +375,8 @@ If you continue to the next tutorial, can keep the resources created in this qui
256
375
257
376
Get the [Node.js quickstart](https://github.com/Azure-Samples/azure-cache-redis-samples/tree/main/quickstart/nodejs) on GitHub.
258
377
259
-
## Next steps
378
+
## Related content
260
379
261
380
In this quickstart, you learned how to use Azure Cache for Redis from a Node.js application. Continue to the next quickstart to use Azure Cache for Redis with an ASP.NET web app.
262
381
263
-
> [!div class="nextstepaction"]
264
-
> [Create an ASP.NET web app that uses an Azure Cache for Redis.](./cache-web-app-howto.md)
382
+
- [Create an ASP.NET web app that uses an Azure Cache for Redis.](./cache-web-app-howto.md)
0 commit comments