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

✨ 454 - Add refresh token logic to Axios client #462

Merged
merged 10 commits into from
Nov 26, 2024

Conversation

anncatton
Copy link
Contributor

@anncatton anncatton commented Oct 15, 2024

Adds refresh token logic to EGA Axios client + updates for API pagination fix

EGA Client

  • adds access token getter function getAccessToken to manage current token used in the client
  • renames access token api call to fetchAccessToken for clarity. Adds error logs here to track the network connection error that has been occurring intermittently; proper error handling + retry functionality will be added in Add Failure Handling & Retry Mechanism to EGA Integration Flow #455
  • removes fetch call refreshAccessToken - new tokens will be retrieved directly from the /token endpoint with fetchAccessToken
  • corrects logic in axios interceptor to reset the current access token used in the client
  • replaces getPermissionByDatasetAndUserId with getPermissionsByUserId.

Permissions service

  • updates processPermissionsForApprovedUsers to use getPermissionsByUserId. Now that the api pagination bug (mentioned in this TODO) has been fixed, the GET /permissions endpoint allows querying for all permissions for a user in one request, using parameters user_id and a limit equal to the total number of datasets in the relevant DAC.
  • simplifies the looping logic in the above function to account for this change
  • removes the temporary fix of offset = offset + DEFAULT_OFFSET - 1 incrementing for pagination in same function

Main EGA Job

Copy link
Member

@joneubank joneubank left a comment

Choose a reason for hiding this comment

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

Cool stuff in here.

Comment on lines 148 to 150
if (currentToken) {
return currentToken;
}
Copy link
Member

Choose a reason for hiding this comment

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

Idea for future, can check within this block if the stored currentToken is expired, and if so we can start a refresh instead of returning the expired token.

// Handle token refresh error
throw refreshError;
if (!refreshTokenPromise) {
resetAccessToken();
Copy link
Member

Choose a reason for hiding this comment

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

👍
might be worth a comment to say "401 indicates that the stored access token is no longer valid"

@@ -44,7 +44,7 @@ export const createRequiredPermissions = async (
egaClient: EgaClient,
approvedUser: EgaDacoUser,
requests: PermissionRequest[],
) => {
): Promise<number | undefined> => {
Copy link
Member

Choose a reason for hiding this comment

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

After reading the descriptio9n and this return type, I don't know what this returns. Why is it a number, why might it be undefined?

// In practice this means that paging will stop before all unique elements are returned, as some of the total is made up of these duplicate values
// Temp solution is to subtract 1 from the offset (limit - 1), which "backtracks" the paging to ensure the element that gets missed in the last array position is captured
offset = offset + DEFAULT_OFFSET - 1;
offset = offset + DEFAULT_OFFSET;
Copy link
Member

Choose a reason for hiding this comment

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

👍

@anncatton anncatton merged commit a227b1e into 452-ega-auth-client Nov 26, 2024
2 checks passed
@anncatton anncatton deleted the add-refresh-token-flow branch November 26, 2024 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants