Migrate MicrosoftAPIRefreshAccessTokenService to @azure/msal-node#16954
Migrate MicrosoftAPIRefreshAccessTokenService to @azure/msal-node#16954charlesBochet merged 4 commits intomainfrom
MicrosoftAPIRefreshAccessTokenService to @azure/msal-node#16954Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
...nt/refresh-tokens-manager/drivers/microsoft/services/microsoft-api-refresh-tokens.service.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/drivers/microsoft/services/microsoft-api-refresh-tokens.service.ts">
<violation number="1" location="packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/drivers/microsoft/services/microsoft-api-refresh-tokens.service.ts:5">
P1: Using `import type` for `TwentyConfigService` may break NestJS dependency injection. Type-only imports are erased at compile time, which can prevent TypeScript from emitting the design-time type metadata that NestJS needs for constructor injection. Use a regular import to match the pattern in the Google service.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| import { ConfidentialClientApplication } from '@azure/msal-node'; | ||
|
|
||
| import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service'; | ||
| import type { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service'; |
There was a problem hiding this comment.
P1: Using import type for TwentyConfigService may break NestJS dependency injection. Type-only imports are erased at compile time, which can prevent TypeScript from emitting the design-time type metadata that NestJS needs for constructor injection. Use a regular import to match the pattern in the Google service.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/twenty-server/src/modules/connected-account/refresh-tokens-manager/drivers/microsoft/services/microsoft-api-refresh-tokens.service.ts, line 5:
<comment>Using `import type` for `TwentyConfigService` may break NestJS dependency injection. Type-only imports are erased at compile time, which can prevent TypeScript from emitting the design-time type metadata that NestJS needs for constructor injection. Use a regular import to match the pattern in the Google service.</comment>
<file context>
@@ -1,67 +1,53 @@
+import { ConfidentialClientApplication } from '@azure/msal-node';
-import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
+import type { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
import {
ConnectedAccountRefreshAccessTokenException,
</file context>
| import type { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service'; | |
| import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service'; |
✅ Addressed in d4ecb69
...nt/refresh-tokens-manager/drivers/microsoft/services/microsoft-api-refresh-tokens.service.ts
Show resolved
Hide resolved
| * Extracts the refresh token from the MSAL token cache. | ||
| * @see https://github.com/duolingo/metasearch/blob/3d782bba8c0068461acb442d89e7d555df5d0025/src/oauth.microsoft.ts#L42-L44 | ||
| */ | ||
| private extractMicrosoftRefreshTokenFromCache(): string { |
There was a problem hiding this comment.
While this is not ideal, it should do for now as the serialized token cache is an complex object, and it's not backwards compatible with our current approach which only stores the raw refresh_token, this would involve creating migration strategies and the other alternative, our old approach (raw HTTP request) wasn't that good either
...nt/refresh-tokens-manager/drivers/microsoft/services/microsoft-api-refresh-tokens.service.ts
Show resolved
Hide resolved
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:37734 This environment will automatically shut down when the PR is closed or after 5 hours. |
| const response = await msalClient.acquireTokenByRefreshToken({ | ||
| refreshToken, | ||
| scopes: ['https://graph.microsoft.com/.default'], | ||
| forceCache: true, |
There was a problem hiding this comment.
During my testing it didn't store the token in TokenCache if this was off
There was a problem hiding this comment.
@neo773
This does not explain the why here:
Per documentation: Force MSAL to cache a refresh token flow response when there is no account in the cache. Used for migration scenarios.
Why do we need it?
| }, | ||
| ); | ||
| const responseData = response.data as MicrosoftRefreshTokenResponse; | ||
| const response = await msalClient.acquireTokenByRefreshToken({ |
There was a problem hiding this comment.
Since this is risky maybe give a bit more details in your PR description, thanks!
There was a problem hiding this comment.
I did add the info here
#16954 (comment)
TLDR;
Microsoft wants you to offload the token lifecycle to their new SDK with a cache storage layer for persisting data.
This data is a proprietary JSON blob and not compatible with our existing schema as it involves heavy changes.
There was a problem hiding this comment.
I'm sorry, I don't understand the rational behind this PR, what are we migrating? why? could you add more details?
FelixMalfait
left a comment
There was a problem hiding this comment.
LGTM but please add details before merging to make sure everything is well considered thanks!
|
Codewise it works but I don't get this change, please add more details why we need this |
No description provided.