Using Redis as ADAL token cache


Here is a sample TokenCache class implementation using Redis for use with the Active Directory Access Library (ADAL). The library is used for obtaining tokens from Azure AD or AD FS using the OAuth2 protocol. This implementation is intended for web applications acting as OAuth2 or OpenIDConnect clients. Typical use of this class is in the AuthenticationContext constructor:

var authContext = new AuthenticationContext(Authority, new RedisTokenCache(signedInUserID));

Note that this is sample code, not intended for production purposes. To use it, you need to provide the Redis connection string in the application’s configuration file with the ‘CacheConnection’ string as key. To acquire tokens from Azure AD your will need to register your app in your AAD tenant. Complete project may be found here: https://github.com/mrochon/RedisTokenCache

 

Comments (2)

  1. Karim says:

    Thank you!, I was searching all the internet for exactly the same thing.
    can’t thank you enough again, please keep posting such great code examples.

    1. SailingRock says:

      Thank you. Good to hear.

Skip to main content