Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6656 Partner refresh tokens #8650

Merged
merged 36 commits into from
Jun 28, 2024
Merged

Conversation

BLoe
Copy link
Contributor

@BLoe BLoe commented Jun 20, 2024

What does this PR do?

Demo

https://www.loom.com/share/ecdd2d683cb74279aa9fa98fe7351c04

Reviewer Tips

  • Main changes are in apiClient.ts, launchAuthIntegration, and refreshPartnerAuthentication

Checklist

  • Add jest or playwright tests and/or storybook stories

Copy link

github-actions bot commented Jun 20, 2024

Playwright test results

passed  80 passed
skipped  2 skipped

Details

report  Open report ↗︎
stats  82 tests across 29 suites
duration  11 minutes, 21 seconds
commit  f1089fa

Skipped tests

chrome › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options
edge › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options

@twschiller twschiller added this to the 2.0.4 milestone Jun 20, 2024
Comment on lines 132 to 143
// // https://developer.chrome.com/docs/extensions/reference/identity/#method-clearAllCachedAuthTokens
// await chromeP.identity.clearAllCachedAuthTokens();

const partnerAuthData = await partnerTokenStorage.get();
if (partnerAuthData?.token) {
console.debug(
"Clearing partner auth for authId: " + partnerAuthData.authId,
);
await chromeP.identity.removeCachedAuthToken({
token: partnerAuthData.token,
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to test this some more to make sure it works properly, but I think we might be able to get away with only clearing the partner token from the identity cache, so that other oauth2 sessions are not invalidated also, like a gsuite login for ex.

@twschiller twschiller added the user experience Improve the user experience (UX) label Jun 20, 2024
console.debug(
"Clearing partner auth for authId: " + partnerAuthData.authId,
);
await removeOAuth2Token(partnerAuthData.token);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave a comment as to why we want this instead of clearAllCachedAuthTokens which we used previously

refreshToken: newRefreshToken as string,
refreshParamPayload: {
...refreshParamPayload,
refresh_token: newRefreshToken as string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To DRY this out, maybe just add the refresh token to postData above so we're not duplicating the refresh token value


let apiClientSetupPromise: Promise<void> | null = null;

async function safeSetupClient(): Promise<void> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions:

  • Why do we need the try/catch block? What kind of errors do we expect to run into? And if there is an error, why not throw it?
  • Why return a promise instead of just returning the axios instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right, not sure what error would ever be thrown from the setup function, so probably don't need the try-catch around that. I had an error being thrown explicitly from inside the setup function at one point when I was working on this, I think that's where this came from.

For the promise question, are you talking about combining the promise and client instance and making it just one stored Promise<AxiosInstance>? Or am I misunderstanding what you are talking about? I suppose I could do it that way with one promise, I'll have to change the code and see if I like how it turns out or not 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind about the promise question. I wasn't understanding it correctly

@twschiller
Copy link
Contributor

@BLoe it looks like there's some merge conflicts now

Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@BLoe BLoe enabled auto-merge (squash) June 28, 2024 06:04
@BLoe BLoe merged commit 441ca9a into main Jun 28, 2024
19 checks passed
@BLoe BLoe deleted the feature/6656-partner-refresh-tokens-take-2 branch June 28, 2024 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enterprise user experience Improve the user experience (UX)
Development

Successfully merging this pull request may close these issues.

Update partner refresh token logic to fetch new access token when expired
4 participants