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
## [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
34
34
35
-
## Enable Microsoft EntraID and add a User or Service Principal
35
+
## Enable Microsoft Entra ID and add a User or Service Principal
36
36
<--Fran, we probably need an include file on enabling EntraID-->
37
37
Blah blah blah, do the steps listed [here](cache-azure-active-directory-for-authentication)
38
38
@@ -45,10 +45,17 @@ npm install @azure/identity
45
45
46
46
## Create a new Node.js app
47
47
48
+
1.Add environment variables for your **Host name** and **Service Principal ID**, which is the object ID your Entra ID service principal or user. In the Azure Portal, this is shown as the _Username_.
49
+
50
+
```cmd
51
+
set AZURE_CACHE_FOR_REDIS_HOST_NAME=contosoCache
52
+
set REDIS_SERVICE_PRINCIPAL_ID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
53
+
```
54
+
48
55
1. Create a new script file named *redistest.js*.
49
56
1. Add the following example JavaScript to the file.
@@ -130,6 +137,113 @@ This code shows you how to connect to an Azure Cache for Redis instance using th
130
137
Done
131
138
```
132
139
140
+
## Create a sample javascript app with reauthentication
141
+
Microsoft EntraID access tokens have limited lifespans, [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.
142
+
143
+
1. Create a new script file named *redistestreauth.js*.
144
+
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)
0 commit comments