Skip to content

Fix invalid scope in Lettuce sample using identity for Redis Cache #45305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ System.out.println(sync.get("Az:testKey"));
* Redis Credential Implementation for Azure Redis for Cache
*/
public static class AzureRedisCredentials implements RedisCredentials {
// Note: The Scopes value will change as the Microsoft Entra authentication support hits public preview and eventually GA's.
private TokenRequestContext tokenRequestContext = new TokenRequestContext()
.addScopes("cca5fbb-b7e4-4009-81f1-37e38fd66d78/.default");
.addScopes("https://redis.azure.com/.default");
private TokenCredential tokenCredential;
private final String username;

Expand Down Expand Up @@ -195,10 +194,9 @@ private static String extractUsernameFromToken(String token) {
DefaultAzureCredential defaultAzureCredential = new DefaultAzureCredentialBuilder().build();

// Fetch a Microsoft Entra token to be used for authentication. The Microsoft Entra token will be used as password.
// Note: The Scopes parameter will change as the Microsoft Entra authentication support hits public preview and eventually GA's.
String token = defaultAzureCredential
.getToken(new TokenRequestContext()
.addScopes("cca5fbb-b7e4-4009-81f1-37e38fd66d78/.default")).block().getToken();
.addScopes("https://redis.azure.com/.default")).block().getToken();

String username = extractUsernameFromToken(token);

Expand Down Expand Up @@ -340,7 +338,6 @@ private static RedisClient createLettuceRedisClient(String hostName, int port, T
* Redis Credential Implementation for Azure Redis for Cache
*/
public static class AzureRedisCredentials implements RedisCredentials {
// Note: The Scopes parameter will change as the Microsoft Entra authentication support hits public preview and eventually GA's.
private TokenRequestContext tokenRequestContext = new TokenRequestContext()
.addScopes("https://redis.azure.com/.default");
private TokenCredential tokenCredential;
Expand Down Expand Up @@ -426,7 +423,6 @@ private static String extractUsernameFromToken(String token) {
DefaultAzureCredential defaultAzureCredential = new DefaultAzureCredentialBuilder().build();

// Fetch a Microsoft Entra token to be used for authentication. This token will be used as the password.
// Note: The Scopes parameter will change as the Microsoft Entra authentication support hits public preview and eventually GA's.
TokenRequestContext trc = new TokenRequestContext().addScopes("https://redis.azure.com/.default");
AccessToken accessToken = getAccessToken(defaultAzureCredential, trc);

Expand Down Expand Up @@ -773,7 +769,6 @@ private static String extractUsernameFromToken(String token) {
DefaultAzureCredential defaultAzureCredential = new DefaultAzureCredentialBuilder().build();

// Fetch a Microsoft Entra token to be used for authentication. This token will be used as the password.
// Note: The Scopes parameter will change as the Microsoft Entra authentication support hits public preview and eventually GA's.
TokenRequestContext trc = new TokenRequestContext().addScopes("https://redis.azure.com/.default");

// Instantiate the Token Refresh Cache, this cache will proactively refresh the access token 2 minutes before expiry.
Expand Down