You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
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
26 lines
715 B
TypeScript
26 lines
715 B
TypeScript
import {
|
|
AuthenticationResult
|
|
} from '@azure/msal-node';
|
|
import { IdentityProvider, TokenResponse } from '@redis/client/dist/lib/authx';
|
|
|
|
export class MSALIdentityProvider implements IdentityProvider<AuthenticationResult> {
|
|
private readonly getToken: () => Promise<AuthenticationResult>;
|
|
|
|
constructor(getToken: () => Promise<AuthenticationResult>) {
|
|
this.getToken = getToken;
|
|
}
|
|
|
|
async requestToken(): Promise<TokenResponse<AuthenticationResult>> {
|
|
const result = await this.getToken();
|
|
|
|
if (!result?.accessToken || !result?.expiresOn) {
|
|
throw new Error('Invalid token response');
|
|
}
|
|
return {
|
|
token: result,
|
|
ttlMs: result.expiresOn.getTime() - Date.now()
|
|
};
|
|
}
|
|
|
|
}
|