Commit 7ac6585
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- packages/seedless-onboarding-controller
- src
8 files changed
+433
-268
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
10 | 24 | | |
11 | 25 | | |
12 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
0 commit comments