| 4 | import { IdentityProvider, TokenResponse } from '@redis/client/dist/lib/authx'; |
| 5 | |
| 6 | export class MSALIdentityProvider implements IdentityProvider<AuthenticationResult> { |
| 7 | private readonly getToken: () => Promise<AuthenticationResult>; |
| 8 | |
| 9 | constructor(getToken: () => Promise<AuthenticationResult>) { |
| 10 | this.getToken = getToken; |
| 11 | } |
| 12 | |
| 13 | async requestToken(): Promise<TokenResponse<AuthenticationResult>> { |
| 14 | const result = await this.getToken(); |
| 15 | |
| 16 | if (!result?.accessToken || !result?.expiresOn) { |
| 17 | throw new Error('Invalid token response'); |
| 18 | } |
| 19 | return { |
| 20 | token: result, |
| 21 | ttlMs: result.expiresOn.getTime() - Date.now() |
| 22 | }; |
| 23 | } |
| 24 | |
| 25 | } |
nothing calls this directly
no outgoing calls
no test coverage detected