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
[Lettuce 6.6.0](https://github.com/redis/lettuce/releases/tag/6.6.0.RELEASE) extends `RedisCredentialsProvider` to support streaming credentials.
242
+
It is useful when you need to refresh credentials periodically. Example use cases include: token expiration, rotating credentials, etc.
243
+
Connection configured with `RedisCredentialsProvider` supporting streaming will be re-authenticated automatically when new credentials are emitted and `ReauthenticateBehavior` is set to `ON_NEW_CREDENTIALS`.
244
+
245
+
### Step 1 - Create a Streaming Credentials Provider
246
+
A simple example of a streaming credentials provider that emits new credentials.
[Lettuce 6.6.0](https://github.com/redis/lettuce/releases/tag/6.6.0.RELEASE) introduces built-in support for authentication with [Azure Managed Redis](https://azure.microsoft.com/en-us/products/managed-redis) and Azure Cache for Redis using Microsoft Entra ID (formerly Azure Active Directory). It enables seamless integration with Azure's Redis services by fetching authentication tokens and managing the token renewal in the background.
311
+
Integration is built on top of [redis-authx](https://github.com/redis/jvm-redis-authx-entraid) library, and provides support for:
312
+
313
+
- System-assigned managed identity
314
+
- User-assigned managed identity
315
+
- Service principal
316
+
317
+
You can learn more about managed identities in the [Microsoft Entra ID documentation](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview).
318
+
319
+
### Basic Usage
320
+
321
+
#### Pre-requisites
322
+
*[register an application and create a service principal](https://learn.microsoft.com/en-us/entra/identity-platform/app-objects-and-service-principals?tabs=browser) in Azure.
323
+
* Create a Redis cache in Azure and grant your service principal access: [AMR](https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/managed-redis/managed-redis-entra-for-authentication) or [ACR](https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-azure-active-directory-for-authentication) documentation.
324
+
325
+
#### Step 1 - Add the dependencies
326
+
Lettuce requires [redis-authx-entraid](https://github.com/redis/jvm-redis-authx-entraid/) dependency to provide Microsoft Entra ID authentication support. Make sure to include that dependency on your classpath.
327
+
328
+
If using Maven, add the following dependency to your `pom.xml`:
329
+
330
+
```xml
331
+
<dependency>
332
+
<groupId>redis.clients.authentication</groupId>
333
+
<artifactId>redis-authx-entraid</artifactId>
334
+
<version>0.1.1-beta1</version>
335
+
</dependency>
336
+
```
337
+
338
+
339
+
### Step 2 - Create Entra ID enabled credentials provider
340
+
The lifecycle of the credentials provider is not managed by the Lettuce client. You can create it once and reuse it across multiple clients\connections. When no longer needed, you should close the provider to release resources `TokenBasedRedisCredentialsProvider#close`.
341
+
342
+
#### Create Microsoft Entra ID enabled credentials provider
343
+
```java
344
+
// Entra ID enabled credentials provider for Service Principle Identity with Client Secret
You can test the credentials provider by obtaining a token.
356
+
357
+
```java
358
+
// Test Entra ID credentials provider can resolve credentials
359
+
credentialsSP.resolveCredentials()
360
+
.doOnNext(c->System.out.println(c.getUsername()))
361
+
.block();
362
+
```
363
+
364
+
### Step 3 - Enable automatic re-authentication
365
+
Microsoft Entra ID tokens have a limited lifetime. Lettuce provides a mechanism to automatically re-authenticate when new credentials are emitted by a `RedisCredentialsProvider`.
0 commit comments