Skip to content

Fixed local storage auth token being retrieved incorrectly #172

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

Conversation

lauraneto
Copy link
Contributor

I've been using these helpers in the integration tests of my package.
When I was testing V15 locally, I kept getting this error:

SyntaxError: Unexpected non-whitespace character after JSON at position 4

    at ApiHelpers.getRefreshToken (D:\Projects\Umbraco.Community.DeliveryApiExtensions\tests\UmbracoDeliveryApiExtensions.Playwright\node_modules\@umbraco\playwright-testhelpers\lib\helpers\ApiHelpers.ts:205:27)
    at ApiHelpers.refreshAccessToken (D:\Projects\Umbraco.Community.DeliveryApiExtensions\tests\UmbracoDeliveryApiExtensions.Playwright\node_modules\@umbraco\playwright-testhelpers\lib\helpers\ApiHelpers.ts:250:26)
    at Object.umbracoApi (D:\Projects\Umbraco.Community.DeliveryApiExtensions\tests\UmbracoDeliveryApiExtensions.Playwright\node_modules\@umbraco\playwright-testhelpers\lib\helpers\testExtension.ts:11:5)

When I checked the ApiHelpers code, I noticed that several calls were assuming that the auth token would be in index 0 of origins, which wasn't the case for me:

{
  ...
  "origins": [
    {
      "origin": "https://localhost:44363",
      "localStorage": [
        {
          "name": "umb:serverUpgradeCheck",
          "value": "{\"type\":\"None\",\"comment\":\"\",\"url\":\"\",\"expires\":\"2024-11-22T21:02:48.808Z\"}"
        },
        {
          "name": "umb:lastUpgradeCheck",
          "value": "2024-11-15T21:02:48.436Z"
        },
        {
          "name": "umb:userAuthTokenResponse",
          "value": "{\"access_token\":\"...\",\"scope\":\"offline_access\",\"token_type\":\"Bearer\",\"issued_at\":1731704598,\"expires_in\":\"3600\"}"
        }
      ]
    }
  ]
}

This fixes #160.

Copy link
Contributor

@andr317c andr317c left a comment

Choose a reason for hiding this comment

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

Looks good to me!💪

@andr317c andr317c merged commit 0802c02 into umbraco:v15/dev Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants