How to access the Redis from another tenant with Entra ID authenticcation

Kefei Qian 40 Reputation points Microsoft Employee
2025-05-26T13:54:55.28+00:00

Hi Team,

I have an App Service in Tenant A that needs to access a Redis instance in Tenant B. To enable this, I created a Service Principal in Tenant B, linked to a multi-tenant app registered in Tenant A, and granted it the Redis Data Contributor role.

However, when attempting to connect to the Redis instance using Python and MSAL on my local machine, I encounter an error indicating an invalid username-password pair. For authentication, I'm using the Service Principal's Object ID as the username and a token obtained via the Azure.Identity library (ConfidentialClientApplication) as the password.

Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
305 questions
{count} votes

Accepted answer
  1. Vijayalaxmi Kattimani 3,250 Reputation points Microsoft External Staff Moderator
    2025-05-26T14:50:18.4466667+00:00

    Hi Kefei Qian

    Greetings!

    As we understand that, you are trying to connect to a Redis instance in another tenant using Entra ID authentication but are running into an issue with the authentication process. 

    Here are a few things to check:

    from azure.identity import ConfidentialClientApplication
     
    client = ConfidentialClientApplication(
        client_id='YOUR_CLIENT_ID',
        client_secret='YOUR_CLIENT_SECRET',
        authority='https://login.microsoftonline.com/YOUR_TENANT_ID'
    )
     
    token_response = client.acquire_token_for_client(scopes=["https://redis.azure.com/.default"])
    
    • Authorization Command: After obtaining the token, ensure that your Redis client sends an AUTH command to authenticate with the Redis server using the Object ID as the user and the token as the password.
    • Token Expiry Management: Implement a mechanism to refresh the token before it expires to avoid connection disruptions. It’s recommended to fetch a new token at least 3 minutes prior to expiry.
    • Firewall and Private Link Configuration: If applicable, make sure that your Redis instance allows traffic from your App Service in Tenant A, which may involve configuring firewall rules or private endpoints.

    I would request you to refer the below mentioned links for more information.

    https://github.com/redis/redis-py-entraid

    https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/samples/azure-aad-auth-with-redis-py.md

    I hope this information helps. Please do let us know if you have any further queries.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.