Skip to content

Commit 7ac6585

Browse files
authored
fix: token errors and refactors (#6998)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> This PR fixes `Invalid AccessToken` issue for the Social login users and also includes the following changes ~ - Refactor `refreshAuthTokens` method, separately catch `refreshJWTToken` and `authenticate` errors - Added new public method, `checkIsSeedlessOnboardingUserAuthenticated`, to validate the authentication state and tokens. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> * Fixes MetaMask/metamask-extension#37337 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Refactors auth token handling with retry/refresh, adds `checkIsSeedlessOnboardingUserAuthenticated`, makes `authenticate` require `refreshToken` and `revokeToken`, fixes access-token rehydration, and bumps `@metamask/toprf-secure-backup` to 0.10.0. > > - **Controller/auth flow**: > - Add public `checkIsSeedlessOnboardingUserAuthenticated()` to validate/set `isSeedlessOnboardingUserAuthenticated`. > - BREAKING: `authenticate` now requires `refreshToken` and `revokeToken`; state updated to persist them along with `accessToken`/`metadataAccessToken`. > - Generalize token error detection to `#isAuthTokenError` (handles `AuthTokenExpired` and `InvalidAuthToken`); wrap more ops with `#executeWithTokenRefresh` (e.g., `fetchAllSecretData`). > - Refactor `refreshAuthTokens()` to separately handle refresh vs re-auth errors; introduce `FailedToRefreshJWTTokens` error. > - Remove `#getAccessToken`; vault/decrypt path now surfaces tokens via `#unlockVaultAndGetVaultData`. > - Fix access-token handling during rehydration (vault creation/restore). > - **Assertions/types**: > - Introduce `assertIsAuthUserInfoValid`; tighten `assertIsSeedlessOnboardingUserAuthenticated` to require `revokeToken` and `accessToken`. > - Update `AuthenticatedUserDetails` to include required `revokeToken` and `accessToken`. > - **Dependencies**: > - Bump `@metamask/toprf-secure-backup` to `0.10.0` (and transitives). > - **Tests**: > - Expand coverage for token refresh/retry paths, new auth check, and error cases; adjust expectations for new errors and required params. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0d0db1a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent e3af02a commit 7ac6585

File tree

8 files changed

+433
-268
lines changed

8 files changed

+433
-268
lines changed

packages/seedless-onboarding-controller/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added new public method, `checkIsSeedlessOnboardingUserAuthenticated` to validate the controller authenticate tokens state. ([#6998](https://github.com/MetaMask/core/pull/6998))
13+
14+
### Changed
15+
16+
- **BREAKING** Update `refreshToken` and `revokeToken` params as required in `Authenticate` method. ([#6998](https://github.com/MetaMask/core/pull/6998))
17+
- Refactor `refreshAuthTokens` method, separately catch refreshJWTToken and authenticate errors. ([#6998](https://github.com/MetaMask/core/pull/6998))
18+
- Bump `@metamask/toprf-secure-backup` package to `0.10.0`. ([#6998](https://github.com/MetaMask/core/pull/6998))
19+
20+
### Fixed
21+
22+
- Fixed `Invalid Access Token` error during rehydration. ([#6998](https://github.com/MetaMask/core/pull/6998))
23+
1024
## [5.0.0]
1125

1226
### Changed

packages/seedless-onboarding-controller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@metamask/auth-network-utils": "^0.3.0",
5151
"@metamask/base-controller": "^9.0.0",
5252
"@metamask/messenger": "^0.3.0",
53-
"@metamask/toprf-secure-backup": "^0.7.1",
53+
"@metamask/toprf-secure-backup": "^0.10.0",
5454
"@metamask/utils": "^11.8.1",
5555
"@noble/ciphers": "^1.3.0",
5656
"@noble/curves": "^1.9.2",

0 commit comments

Comments
 (0)