1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00
Files
node-redis/packages/entraid/lib/azure-identity-provider.ts
Bobby I. 8b4ed0059a feat(entraid): add support for azure identity (#2901)
This PR adds support for using Azure Identity's credential classes with Redis Enterprise Entra ID authentication.
The main changes include:

- Add a new factory method createForDefaultAzureCredential to enable using Azure Identity credentials
- Add @azure/identity as a dependency to support the new authentication flow
- Add support for DefaultAzureCredential, EnvironmentCredential, and any other TokenCredential implementation
- Create a new AzureIdentityProvider to support DefaultAzureCredential
- Update documentation and README with usage examples for DefaultAzureCredential
- Add integration tests for the new authentication methods
- Include a sample application demonstrating interactive browser authentication
- Export constants for Redis scopes / credential mappers to simplify authentication configuration
2025-03-05 14:47:18 +02:00

23 lines
566 B
TypeScript

import type { AccessToken } from '@azure/core-auth';
import { IdentityProvider, TokenResponse } from '@redis/client/dist/lib/authx';
export class AzureIdentityProvider implements IdentityProvider<AccessToken> {
private readonly getToken: () => Promise<AccessToken>;
constructor(getToken: () => Promise<AccessToken>) {
this.getToken = getToken;
}
async requestToken(): Promise<TokenResponse<AccessToken>> {
const result = await this.getToken();
return {
token: result,
ttlMs: result.expiresOnTimestamp - Date.now()
};
}
}