From 85e76520fb9387bc6cd75984d296c96fae9fb72a Mon Sep 17 00:00:00 2001 From: Suleiman Latrsh Date: Fri, 21 Aug 2026 15:44:01 -0400 Subject: [PATCH] Create new Release. Assisted-By: devx/1a78381e-f26b-4af8-8e37-b02651ec084a --- CHANGELOG.md | 13 + README.md | 431 ++++++++++++------ composer.json | 2 +- src/Internal/Verify/AdminUIExt.php | 18 +- src/Internal/Verify/AppHomeReq.php | 28 +- .../Verify/NonExchangeableIdToken.php | 2 +- src/Internal/Verify/PosUIExt.php | 18 +- src/Types/ResultWithExchangeableIdToken.php | 2 +- src/Version.php | 2 +- 9 files changed, 337 insertions(+), 179 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b02d2d6..3fa5a67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,24 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.0] + +- **Breaking:** rename the verify result field `newIdTokenResponse` to `invalidTokenResponse`, matching the `exchangeUsingTokenExchange` and `adminGraphQLRequest` parameters. Update any code that reads this field: + + ```diff + - $result->newIdTokenResponse + + $result->invalidTokenResponse + ``` + +- Widen the `guzzlehttp/guzzle` constraint to `^7.0 || ^8.0` so installs on projects that pull Guzzle 8 (such as Laravel 13) resolve without error. + ## [0.1.5] - Verify the dest property is not a malicious URL before making a token exchange request - Reject App Proxy requests with multiple `shop` query parameters with a 401 response. - Refreshing a non-expiring token now returns a no-refresh-needed result instead of an error +- Checkout UI and Customer Account UI Extension requests now return `shop` without the `https://` prefix +- Update the README for the package ## [0.1.4] diff --git a/README.md b/README.md index b078359..6d7171d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,42 @@ PHP package for building Shopify applications. +This package encodes the secure, correct way to build a Shopify app. Most of what you need is already handled for you. The guidance below is written so you use the built-in path and do not reimplement (less safely) things the package already does. If you are ever tempted to parse, verify, or refresh something yourself, check the [Common misuses to avoid](#common-misuses-to-avoid) section first. + +> **Upgrading from [`shopify/shopify-api`](https://github.com/Shopify/shopify-api-php)?** This is a new, framework-agnostic package with a different API, designed for incremental adoption. Adopt it gradually, one route at a time. Breaking changes between releases are listed in the [CHANGELOG](CHANGELOG.md). + +## Contents + +- [Prerequisites](#prerequisites) +- [Installation](#installation) +- [Requirements](#requirements) +- [Features](#features) +- [Principles](#principles) +- [Start here (the green path)](#start-here-the-green-path) +- [Setup steps](#setup-steps) +- [Using the package](#using-the-package) + - [Initialization](#initialization) + - [Converting a request](#converting-a-request) + - [Converting a Shopify response](#converting-a-shopify-response) + - [The verify result](#the-verify-result) + - [Getting the shop](#getting-the-shop) + - [Verifying requests with exchangeable ID tokens](#verifying-requests-with-exchangeable-id-tokens) + - [Navigating inside and outside the App Home iframe](#navigating-inside-and-outside-the-app-home-iframe) + - [GraphQL requests](#graphql-requests) + - [Verifying requests without exchangeable ID tokens](#verifying-requests-without-exchangeable-id-tokens) + - [Getting access tokens with client credentials](#getting-access-tokens-with-client-credentials) +- [Common misuses to avoid](#common-misuses-to-avoid) +- [Contributing, issues, feedback and feature requests](#contributing-issues-feedback-and-feature-requests) + +## Prerequisites + +Before you start, make sure you have: + +- A [Shopify Partner account](https://partners.shopify.com) and a development store +- The [Shopify CLI](https://shopify.dev/docs/api/shopify-cli#installation) installed +- PHP 8.2+ and [Composer](https://getcomposer.org) +- A web framework project (Laravel, Symfony, CodeIgniter, or plain PHP) + ## Installation ```bash @@ -16,6 +52,8 @@ composer require shopify/shopify-app-php ## Features +Each function encodes a piece of the secure green path. Use the listed function rather than building your own version. + Request Verification: - `verifyAdminUIExtReq`: Requests from Admin UI extensions @@ -31,7 +69,7 @@ Exchange: - `exchangeUsingTokenExchange`: Use Token Exchange to exchange an ID token for an access token - `exchangeUsingClientCredentials`: Get access tokens via client credentials -- `refreshTokenExchangedAccessToken`: Refresh an access token that was created using Token Exchange +- `refreshTokenExchangedAccessToken`: Refresh an access token that was created using Token Exchange. Checks if a token refresh can and should happen. GraphQL: @@ -39,7 +77,7 @@ GraphQL: Helpers: -- `appHomePatchIdToken`: Render the patch ID token page for embedded apps +- `appHomePatchIdToken`: Securely renders the HTML to refresh a stale ID token. Use this instead of your own logic. - `appHomeParentRedirect`: Asks the parent (Shopify admin) to redirect to a new URL, breaking out of the iframe - `appHomeRedirect`: Redirects to a relative URL within the app home iframe @@ -50,19 +88,22 @@ Helpers: 3. **Framework agnostic:** Whether you're using Laravel, Symfony, CodeIgniter, or raw PHP, these packages won't force architectural decisions on you. We provide primitives. You compose them however you wish. We've prototyped extensively to make sure that composition can lead to idiomatic patterns. 4. **Language agnostic:** Whilst this is a PHP package, its API is shared with a Python package. This creates some interesting constraints, and sacrifices some idioms. But... the big benefit is that fixes in one community will benefit the other. As the Python package evolves, so will the PHP package (and vice-versa). -## Setup steps +## Start here (the green path) -This section will focus on steps that are universal to any web framework. We'll provide examples for Laravel, Symfony and CodeIgniter. But these examples are fairly universal and can be translated to other approaches. +Most apps follow the same path on every request from Shopify: -### Install the Shopify CLI +1. Convert your framework's request into the package's request shape. +2. Verify the request with the matching `verify...` function. +3. If `ok` is `false`, return the provided `response`. +4. Use `$result->shop` to look up or store the shop's access token. +5. Exchange or refresh the token when needed. +6. Make Admin GraphQL calls, passing the retry response the package gave you. -This installs Shopify CLI globally on your system, so you can run shopify commands from any directory. +Every step below has a built-in function. Use it. The recurring rule in this README: if the package already gives you a value or a response, use that value or response. Do not parse, craft, or re-verify it yourself. -``` -npm install -g @shopify/cli@latest -``` +## Setup steps -Please see [this guide](https://shopify.dev/docs/api/shopify-cli#installation) for using other JavaScript package managers +This section will focus on steps that are universal to any web framework. We'll provide examples for Laravel, Symfony and CodeIgniter. But these examples are fairly universal and can be translated to other approaches. ### Initialize your web framework @@ -95,7 +136,7 @@ Make sure there is at-least a minimal `package.json`: } ``` -Create a `shopify.web.toml`: +Create a `shopify.web.toml`. The Shopify CLI needs this file to know how to serve your app during development. Set `roles` and the `dev` command so the CLI can serve and proxy your app. ```toml name = "My PHP App" @@ -141,11 +182,27 @@ $shopify = new ShopifyApp( ); ``` -For secret rotation, `oldClientSecret` is an optional parameter. Since the CLI does not provide this env var, you will need to provide it manually. Read more about [secret rotation](https://shopify.dev/docs/apps/build/authentication-authorization/client-secrets/rotate-revoke-client-credentials). +For secret rotation, `oldClientSecret` is an optional parameter. Since the CLI does not provide this env var, you will need to provide it manually. Requests signed with either the current or the old secret are accepted while you roll the secret out, so you avoid downtime during rotation. Read more about [secret rotation](https://shopify.dev/docs/apps/build/authentication-authorization/client-secrets/rotate-revoke-client-credentials). + +```php +$shopify = new ShopifyApp( + clientId: getenv('SHOPIFY_API_KEY'), + clientSecret: getenv('SHOPIFY_API_SECRET'), + oldClientSecret: getenv('SHOPIFY_OLD_API_SECRET'), +); +``` + +**Do** set `oldClientSecret` while rotating a secret, then remove it once the rotation is complete. + +**Don't** roll a secret without it. If you swap the secret in one step, in-flight requests signed with the previous secret will fail verification. -### Converting a Request +### Converting a request -So that the package can support multiple frameworks, your app must convert your frameworks concept of a Request to the package's concept. +So that the package can support multiple frameworks, your app must convert your framework's concept of a Request to the package's concept. + +**Do** pass the raw request through unchanged: the method, all headers, the full URL including query string, and the unmodified body. + +**Don't** filter headers, drop query parameters, or re-encode the body. Verification depends on the exact bytes Shopify sent. Altering them causes valid requests to fail verification. Laravel Example: @@ -194,7 +251,7 @@ function requestToShopifyReq($request) ### Converting a Shopify response -Your app must convert the packages concept of a Response to the frameworks concept. The Result provided by the package's function also includes a `log` property with these properties: +Your app must convert the package's concept of a Response to the framework's concept. The Result provided by the package's function also includes a `log` property with these properties: - `code`: A short string describing the situation - `detail`: Copy describing the state of the request and what you should do next. @@ -202,6 +259,10 @@ Your app must convert the packages concept of a Response to the frameworks conce We recommend logging this information to help you debug. +**Do** return the package's `response` verbatim, including its `status`, `body`, and `headers`. + +**Don't** build your own response for failures or drop the headers. The package's response carries the correct status and the security headers Shopify requires (see [Getting the shop](#getting-the-shop) and the App Home section for why this matters). + Laravel example: ```php @@ -210,12 +271,12 @@ use Illuminate\Http\Response; function shopifyResultToResponse($result) { - $log = $result['log']; - Log::info("{$log['code']} - {$log['detail']}"); + $log = $result->log; + Log::info("{$log->code} - {$log->detail}"); - $resp = $result['response']; - return response($resp['body'], $resp['status']) - ->withHeaders($resp['headers']); + $resp = $result->response; + return response($resp->body, $resp->status) + ->withHeaders((array) $resp->headers); } ``` @@ -227,14 +288,14 @@ use Symfony\Component\HttpFoundation\Response; function shopifyResultToResponse($result, LoggerInterface $logger) { - $log = $result['log']; - $logger->info("{$log['code']} - {$log['detail']}"); + $log = $result->log; + $logger->info("{$log->code} - {$log->detail}"); - $resp = $result['response']; + $resp = $result->response; return new Response( - $resp['body'], - $resp['status'], - $resp['headers'] + $resp->body, + $resp->status, + (array) $resp->headers ); } ``` @@ -246,45 +307,55 @@ use CodeIgniter\HTTP\Response; function shopifyResultToResponse($result) { - $log = $result['log']; - log_message('info', "{$log['code']} - {$log['detail']}"); + $log = $result->log; + log_message('info', "{$log->code} - {$log->detail}"); - $resp = $result['response']; + $resp = $result->response; return service('response') - ->setStatusCode($resp['status']) - ->setBody($resp['body']) - ->setHeaders($resp['headers']); + ->setStatusCode($resp->status) + ->setBody($resp->body) + ->setHeaders((array) $resp->headers); } ``` -### Verifying request result +### The verify result Verifying a request returns a `Result`. A `Result` is similar across all verify functions, with some differences. Common properties (all verify functions): -| Property | Description | Nullable | -| ---------- | ------------------------------------------------------------------------------------------------------ | -------- | -| `ok` | Boolean indicating if the request passed verification. Respond with the Response if `false` | No | -| `shop` | The shop sub domain (e.g: `test-shop`, for `test-shop.myshopify.com`). `null` when verification fails. | Yes | -| `log` | Object containing `code`, `detail`, and `req` for debugging and monitoring. | No | -| `response` | Pre-built HTTP response with `status`, `body`, and `headers`. Return this when `ok` is `false`. | No | +| Property | Description | Nullable | +| --- | --- | --- | +| `ok` | Boolean indicating if the request passed verification. Respond with the Response if `false` | No | +| `shop` | The shop sub domain (e.g: `test-shop`, for `test-shop.myshopify.com`). `null` when verification fails. Already parsed correctly for the request type and verified. Always use this value. See [Getting the shop](#getting-the-shop). | Yes | +| `log` | Object containing `code`, `detail`, and `req` for debugging and monitoring. | No | +| `response` | Pre-built HTTP response with `status`, `body`, and `headers`. Return this when `ok` is `false`. Carries required security headers. Return it as-is. | No | Properties for Exchangeable ID Token Requests (`verifyAppHomeReq`, `verifyAdminUIExtReq`, `verifyPosUIExtReq`): -| Property | Description | Nullable | -| -------------------- | ----------------------------------------------------------------------------------- | -------- | -| `userId` | The merchant user ID. `null` if `ok` is `false`. | Yes | -| `idToken` | Object containing `exchangeable` (Boolean), `token` (string), and `claims` (array). | Yes | -| `newIdTokenResponse` | Pre-built response for invalid token retry flow. | Yes | +| Property | Description | Nullable | +| --- | --- | --- | +| `userId` | The merchant user ID. `null` if `ok` is `false`. | Yes | +| `idToken` | Object containing `exchangeable` (Boolean), `token` (string), and `claims` (array). | Yes | +| `invalidTokenResponse` | Pre-built response for the invalid token retry flow. Pass it to `exchangeUsingTokenExchange` and `adminGraphQLRequest` so Shopify can retry requests with a fresh token. | Yes | Properties for App Proxy Requests (`verifyAppProxyReq`): -| Property | Description | Nullable | -| -------------------- | ----------------------------------------------------------------------------------------------------- | -------- | -| `loggedInCustomerId` | The customer ID if logged in. `null` if not logged in. This is a customer ID, not a merchant user ID. | Yes | +| Property | Description | Nullable | +| --- | --- | --- | +| `loggedInCustomerId` | The customer ID if logged in. `null` if not logged in. This is a customer ID, not a merchant user ID. | Yes | + +### Getting the shop -### Verifying Requests with exchangeable ID Tokens +**Do** use `shop` from the verify result. We securely parse it from the request, avoiding known attack vectors. + +**Don't** read the shop from the request yourself (for example by decoding the ID token). That is fragile and skips that protection. + +```php +$shop = $result->shop; // e.g. "test-shop" +``` + +### Verifying requests with exchangeable ID tokens Some requests provide exchangeable ID tokens: @@ -312,44 +383,51 @@ function appHome($request) ); // The request should not be trusted - if (!$result['ok']) { + if (!$result->ok) { return shopifyResultToResponse($result); } ``` +`appHomePatchIdTokenPath` is required on every `verifyAppHomeReq` call. It points at your [token-refresh route](#add-the-token-refresh-route). When a page request arrives without a token, or with a stale one, verify redirects the browser there to get a fresh token, so it needs to know the path. Verify checks it on every call, so pass it even on routes that only ever receive `fetch` requests. An empty or missing value returns a configuration error (HTTP 500). + Then we check if there is an access token in the database. If there is one we check if it needs to be refreshed. ```php // Your database logic here - $accessToken = getAccessToken($result['shop'], 'offline'); + $accessToken = getAccessToken($result->shop, 'offline'); if ($accessToken) { $refreshResult = $shopify->refreshTokenExchangedAccessToken($accessToken); - if (!$refreshResult['ok']) { + if (!$refreshResult->ok) { return shopifyResultToResponse($refreshResult); } - if (isset($refreshResult['accessToken'])) { - // Package returned a refreshed token — save it - saveAccessToken($refreshResult['accessToken']); + if (isset($refreshResult->accessToken)) { + // Package returned a refreshed token, save it + saveAccessToken($refreshResult->accessToken); } } ``` +**Do** call `refreshTokenExchangedAccessToken` and save the token if one is returned. + +**Don't** add your own checks before calling it. It already verifies whether a refresh token exists and whether it has expired, and returns a fresh token only when one is needed. Wrapping it with your own pre-checks just duplicates that logic and risks getting it wrong. + You will need to write the database code to get and save access tokens. The package always returns and accepts access tokens in the same shape: -| Key | Type | Description | -| --------------------- | ------------- | --------------------------------------------------- | -| `shop` | string | Shop domain (e.g., "test-shop.myshopify.com") | -| `accessMode` | string | Access mode: "online" or "offline" | -| `token` | string | The access token | -| `scope` | string | Granted scopes | -| `refreshToken` | string or null | Token used to refresh the access token. `null` for non-expiring tokens. | -| `expires` | string | ISO 8601 datetime when access token expires | +| Key | Type | Description | +| --- | --- | --- | +| `shop` | string | Shop sub domain (e.g., "test-shop") | +| `accessMode` | string | Access mode: "online" or "offline" | +| `token` | string | The access token | +| `scope` | string | Granted scopes | +| `refreshToken` | string or null | Token used to refresh the access token. `null` for non-expiring tokens. | +| `expires` | string or null | ISO 8601 datetime when access token expires. `null` for non-expiring tokens. | | `refreshTokenExpires` | string or null | ISO 8601 datetime when refresh token expires. `null` for non-expiring tokens. | -| `userId` | string | A unique identifier for the user | -| `user` | array or null | User details (online mode only, `null` for offline) | +| `user` | array or null | User details (online mode only, `null` for offline) | + +For the merchant user id, use `$result->userId` from the verify result. Online access tokens also include a `user` object with an `id`; offline tokens have no `user`. When `accessMode` is "online", the `user` array contains: @@ -371,36 +449,42 @@ If there is no access token in the database, use token exchange to get one: if (!$accessToken) { $exchangeResult = $shopify->exchangeUsingTokenExchange( accessMode: 'offline', - idToken: $result['idToken'], - invalidTokenResponse: $result['newIdTokenResponse'], + idToken: $result->idToken, + invalidTokenResponse: $result->invalidTokenResponse, ); - if (!$exchangeResult['ok']) { + if (!$exchangeResult->ok) { return shopifyResultToResponse($exchangeResult); } // Save the new token - saveAccessToken($exchangeResult['accessToken']); + saveAccessToken($exchangeResult->accessToken); } ``` Note: -- `exchangeUsingTokenExchange` receives `$result["newIdTokenResponse"]` from the verify function. This allows Shopify to automatically retry this request if the id token has become stale. +- `exchangeUsingTokenExchange` receives `$result->invalidTokenResponse` from the verify function. Passing it lets Shopify automatically retry the request if the id token has become stale. Whether you pass it depends on the request type (see the GraphQL section). - Pass `expiring: false` to request a non-expiring token (no `refreshToken` or `refreshTokenExpires`). Defaults to `true`. -- If using online access tokens, use the `userId` provided by the `result`. +- If using online access tokens, use the `userId` provided by the verify `result`, not the access token. - If your app has need to access the admin API outside of requests from App Home, Admin UI Extensions or POS UI Extensions you should also exchange and save an offline token. -App home requests require [special Response headers](https://shopify.dev/docs/apps/build/security/set-up-iframe-protection). The `result` provides a response that contains these headers. Copy them to your response: +##### Return the required App Home response headers + +App home requests require [special Response headers](https://shopify.dev/docs/apps/build/security/set-up-iframe-protection) (for example, the `Content-Security-Policy` `frame-ancestors` directive). These headers are what allow your app to load securely inside the Shopify admin iframe. + +**Do** copy the headers from the verify result onto your App Home response: ```php // Copy headers from result to your response -$headers = $result['response']['headers'] ?? []; +$headers = $result->response->headers ?? []; foreach ($headers as $header => $value) { $response->headers->set($header, $value); } ``` +When `ok` is `false`, return the provided `response` as-is. When `ok` is `true`, copy `response.headers` onto your framework's response before rendering App Home. + App requests should also contain [App Bridge](https://shopify.dev/docs/api/app-bridge) and [Polaris Web Components](https://shopify.dev/docs/api/app-home/using-polaris-components) script tags so they remain secure and can look like Shopify: ```html @@ -411,9 +495,13 @@ App requests should also contain [App Bridge](https://shopify.dev/docs/api/app-b ``` -Replace `{{ $clientId }}` with your the `SHOPIFY_API_KEY` provided by the Shopify CLI. +Replace `{{ $clientId }}` with the `SHOPIFY_API_KEY` provided by the Shopify CLI. + +##### Add the token-refresh route + +Add a route that serves the token-refresh (patch ID token) page. This is what makes ordinary link and full-page navigation inside the App Home iframe work: when a navigation reaches your server without a session token, App Bridge uses this route to obtain a fresh one and retry the original request. Skipping it means in-app navigations that arrive without a token cannot recover. -Add a special route for handling some edge cases. Adding this route ensures the merchant experience is resilient: +**Do** use `appHomePatchIdToken` for this route: ```php function patchIdToken($request) @@ -426,7 +514,9 @@ function patchIdToken($request) } ``` -This route should match the path configured here: +**Don't** build your own token-refresh page. By using `appHomePatchIdToken`, your app stays secure against known attack vulnerabilities. + +This route should match the path configured in `verifyAppHomeReq`: ```php $result = $shopify->verifyAppHomeReq( @@ -435,9 +525,31 @@ This route should match the path configured here: ); ``` -Adding this route ensures the merchant experience is resilient to edge cases. +#### Admin UI Extensions + +Admin UI Extension are very similar to App Home. You only need change the verify method: + +```php +$result = $shopify->verifyAdminUIExtReq($req); +``` + +Admin UI extensions do not need the app home patch id token route. They do not need special headers or Polaris and App Bridge. + +#### POS UI Extension + +POS UI Extension are very similar to App Home. You only need change the verify method: + +```php +$result = $shopify->verifyPosUIExtReq($req); +``` + +POS UI extensions do not need the app home patch id token route. They do not need special headers or Polaris and App Bridge. + +### Navigating inside and outside the App Home iframe -#### Redirecting Outside the App Home Iframe +App Home renders inside a cross-origin iframe. Because of this, ordinary links and redirects need care: the iframe cannot rely on cookies, and every authenticated request needs a session token. Use the helpers below rather than building redirects by hand. + +#### Redirecting outside the App Home iframe Use `appHomeParentRedirect` when you need to redirect the merchant to an external URL, breaking out of the app iframe: @@ -448,7 +560,7 @@ function someHandler($request) $req = requestToShopifyReq($request); $result = $shopify->verifyAppHomeReq($req, appHomePatchIdTokenPath: '/auth/patch-id-token'); - if (!$result['ok']) { + if (!$result->ok) { return shopifyResultToResponse($result); } @@ -456,16 +568,16 @@ function someHandler($request) $redirectResult = $shopify->appHomeParentRedirect( $req, redirectUrl: 'https://example.com', - shop: $result['shop'], + shop: $result->shop, ); return shopifyResultToResponse($redirectResult); } ``` -For navigating to admin pages, we recommend using [Admin Intents](https://shopify.dev/docs/apps/build/admin/admin-intents) as this provides the best merchant experience. However, if this is not possible, you can redirect to Shopify admin pages using the `shop` value from the verify result (e.g., `"https://admin.shopify.com/store/{$result['shop']}/products"`). +For navigating to admin pages, we recommend using [Admin Intents](https://shopify.dev/docs/apps/build/admin/admin-intents) as this provides the best merchant experience. However, if this is not possible, you can redirect to Shopify admin pages using the `shop` value from the verify result (e.g., `"https://admin.shopify.com/store/{$result->shop}/products"`). -#### Redirecting Within the App Home Iframe +#### Redirecting within the App Home iframe Use `appHomeRedirect` when you need to redirect to another route within your app, staying inside the app iframe: @@ -476,7 +588,7 @@ function someHandler($request) $req = requestToShopifyReq($request); $result = $shopify->verifyAppHomeReq($req, appHomePatchIdTokenPath: '/auth/patch-id-token'); - if (!$result['ok']) { + if (!$result->ok) { return shopifyResultToResponse($result); } @@ -484,7 +596,7 @@ function someHandler($request) $redirectResult = $shopify->appHomeRedirect( $req, redirectUrl: '/dashboard', - shop: $result['shop'], + shop: $result->shop, ); return shopifyResultToResponse($redirectResult); @@ -493,29 +605,19 @@ function someHandler($request) Note: The redirect URL must be a relative path starting with `/`. URL parameters from the original request are automatically merged into the redirect URL. -#### Admin UI Extensions +#### Authenticated navigation between your own pages -Admin UI Extension are very similar to App Home. You only need change the verify method: +App Bridge attaches the session token to `fetch` and `XMLHttpRequest`, and it intercepts link clicks on `a`, `s-link`, `s-button`, and `s-clickable` elements. It does not intercept same-origin navigations that target the current frame, so an ordinary link or full-page navigation to one of your own pages reaches your server without a session token, and the destination cannot verify the request. -```php -$result = $shopify->verifyAdminUIExtReq($req); -``` - -Admin UI extensions do not need the app home patch id token route. They do not need special headers or Polaris and App Bridge - -#### POS UI Extension - -POS UI Extension are very similar to App Home. You only need change the verify method: +You do not need a single-page app to handle this. As long as you wire the [token-refresh route](#add-the-token-refresh-route) and pass `appHomePatchIdTokenPath` to every `verifyAppHomeReq` call, the package recovers automatically: when a navigation arrives without a token, verify returns a response that redirects to the patch ID token page, App Bridge re-requests the same URL with a fresh token, and the retried request verifies. Standard multi-page apps work this way. -```php -$result = $shopify->verifyPosUIExtReq($req); -``` +Do not pass the ID token as a URL parameter to work around this. The token expires after about a minute, so it goes stale on any later navigation, and tokens in URLs leak into logs, referrers, and browser history. -POS UI extensions do not need the app home patch id token route. They do not need special headers or Polaris and App Bridge +For more detail, see the [App Home documentation](https://shopify.dev/docs/api/app-home). -### GraphQL Requests +### GraphQL requests -The package provides a method for making Admin GraphQL requests. Note, there may be a better more performant ways to access data using Shopify's infrastructure rather than your own: +The package provides a method for making Admin GraphQL requests. Note, there may be a better more performant way to access data using Shopify's infrastructure rather than your own: - App Home has [Direct API](https://shopify.dev/docs/api/app-home#direct-api-access). - Admin UI Extensions have [the Query API](https://shopify.dev/docs/api/admin-extensions/latest/api/target-apis/standard-api#standardapi-propertydetail-query) @@ -523,6 +625,8 @@ The package provides a method for making Admin GraphQL requests. Note, there may - Customer Account UI Extensions can query [the Customer Account API](https://shopify.dev/docs/api/customer-account-ui-extensions/latest/apis/customer-account-api), the [Storefront API](https://shopify.dev/docs/api/customer-account-ui-extensions/latest/apis/storefront-api) and the [Order Status API](https://shopify.dev/docs/api/customer-account-ui-extensions/latest/apis/order-status-api/addresses). - Checkout UI Extensions can query the [Storefront API](https://shopify.dev/docs/api/checkout-ui-extensions/latest/apis/storefront-api) directly. +**Do** prefer the surface-specific data APIs above when you can. **Don't** route data through your own server with `adminGraphQLRequest` when a faster first-party option exists for that surface. + If you do wish to access the Admin GraphQL API on your server, here is how: #### When responding to a request from Shopify @@ -531,7 +635,7 @@ Here is how to make a GraphQL request in the context of a request from Shopify. 1. This example will use an app home request, but it applies to multiple verify methods 2. This example assumes the request is idempotent -3. This examples assumes, that in the event of a failure, you just want Shopify to retry the request. +3. This example assumes, that in the event of a failure, you just want Shopify to retry the request. More details on points 2 & 3 after the code example. @@ -541,13 +645,29 @@ function appHomeHandler($request) $shopify = getShopifyApp(); $req = requestToShopifyReq($request); - $result = $shopify->verifyAppHomeReq($req); - if (!$result['ok']) { + $result = $shopify->verifyAppHomeReq($req, appHomePatchIdTokenPath: '/auth/patch-id-token'); + if (!$result->ok) { return shopifyResultToResponse($result); } // Your database logic here - $accessToken = getAccessToken($result['shop'], 'offline'); + $accessToken = getAccessToken($result->shop, 'offline'); + + // If there is no stored token (for example after a delete & retry, where the token + // was just deleted), exchange one before using it. Otherwise `$accessToken` is null + // and the request below crashes. + if (!$accessToken) { + $exchangeResult = $shopify->exchangeUsingTokenExchange( + accessMode: 'offline', + idToken: $result->idToken, + invalidTokenResponse: $result->invalidTokenResponse, + ); + if (!$exchangeResult->ok) { + return shopifyResultToResponse($exchangeResult); + } + saveAccessToken($exchangeResult->accessToken); + $accessToken = $exchangeResult->accessToken; + } $graphqlResult = $shopify->adminGraphQLRequest( ' @@ -557,50 +677,54 @@ function appHomeHandler($request) } } ', - shop: $result['shop'], - accessToken: $accessToken, + shop: $result->shop, + accessToken: $accessToken->token, apiVersion: '2025-01', - // Passing `$result['newIdTokenResponse']` from the verify function + // Passing `$result->invalidTokenResponse` from the verify function // tells `adminGraphQLRequest` in what context the GraphQL request is being made. // This becomes important if the GraphQL request fails and you wish for Shopify to retry the request. - invalidTokenResponse: $result['newIdTokenResponse'], + invalidTokenResponse: $result->invalidTokenResponse, ); // The GraphQL failed - if (!$graphqlResult['ok']) { + if (!$graphqlResult->ok) { // The access_token is invalid // In this example we take the simplest possible approach // But depending on your logic, you may want a more complex approach // Options are detailed below - if ($graphqlResult['log']['code'] === 'unauthorized') { - deleteAccessToken($result['shop'], 'offline'); + if ($graphqlResult->log->code === 'unauthorized') { + deleteAccessToken($result->shop, 'offline'); } return shopifyResultToResponse($graphqlResult); } - $shopId = $graphqlResult['data']['shop']['id']; + $shopId = $graphqlResult->data['shop']['id']; } ``` -You will get an `unauthorized` log code if: +**Do** branch on the `log` `code` the package returns, as shown above. + +**Don't** invent your own error codes or parse error messages. Branch on the `log` `code` the package returns. -1. The app was uninstalled (unrecoverable) -2. Your app requested additional scopes, but the users has not yet approved them and you are making a graphQL operation that requires the additional scopes. -3. Your access token has been revoked +Some failures are unrecoverable (for example the app was uninstalled), in which case the merchant must reinstall. If the token is valid but the merchant has not approved a required scope, they must approve it (do not retry). If the token is revoked or invalid, you can recover; the options are below. -If 1 happens, the merchant needs to manually reinstall the app. If 2 or 3 happens there are different approaches you can take: +For a revoked or invalid token, there are different approaches you can take: -| Option | Steps | Use when | -| ---------------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- | -| 1. Delete & retry (shown above) | Delete token → return retry response | Request is idempotent. OK for Shopify to auto-retry | -| 2. Exchange & update with retry fallback | Token exchange → update token → retry GraphQL → (on fail) delete token → return retry response | Request is not idempotent. You can revert prior operations. OK for Shopify to auto-retry | -| 3. Exchange with no fallback | Token exchange → update token → retry GraphQL → (on fail) delete token → return non-retry 401 response | Request is not idempotent. It is not OK for Shopify to auto-retry | +| Option | Steps | Use when | +| --- | --- | --- | +| 1. Delete & retry (shown above) | Delete token → return retry response | Request is idempotent. OK for Shopify to auto-retry | +| 2. Exchange & update with retry fallback | Token exchange → update token → retry GraphQL → (on fail) delete token → return retry response | Request is not idempotent. You can revert prior operations. OK for Shopify to auto-retry | +| 3. Exchange with no fallback | Token exchange → update token → retry GraphQL → (on fail) delete token → return non-retry 401 response | Request is not idempotent. It is not OK for Shopify to auto-retry | + +**Note on "Delete & retry":** after you delete the token and return the retry response, App Bridge retries the _same_ request with a fresh session token. That retried request no longer has a stored access token, so the route it lands on must be able to obtain one again (exchange `idToken` from the verify result). If the route only reads a stored token, the retry will fail. The App Home flow above already handles this: it exchanges a token when none is stored. #### In a background job -When making GraphQL requests in a background job (e.g., processing a webhook, scheduled task) pass `null` for `invalidTokenResponse`. if the access token is invalid, the request will simply fail. +When making GraphQL requests in a background job (e.g., processing a webhook, scheduled task) pass `null` for `invalidTokenResponse`. If the access token is invalid, the request will simply fail. + +**Do** pass `null` here. In a background job there is no live request for Shopify to retry, so there is nothing for a retry response to attach to. ```php function processJob($shop) @@ -618,16 +742,16 @@ function processJob($shop) } ', shop: $shop, - accessToken: $accessToken['token'], + accessToken: $accessToken->token, apiVersion: '2025-01', invalidTokenResponse: null, ); - if (!$graphqlResult['ok']) { + if (!$graphqlResult->ok) { return; } - $shopId = $graphqlResult['data']['shop']['id']; + $shopId = $graphqlResult->data['shop']['id']; } ``` @@ -655,7 +779,7 @@ function processJob($shop) - `data`: The GraphQL response data, or `null` if the request failed. - `extensions`: The GraphQL extensions (e.g., cost information), or `null` if not present. -### Verifying requests without exchangeable id tokens +### Verifying requests without exchangeable ID tokens The following requests do not provide the required information for token exchange: @@ -668,6 +792,8 @@ Webhook and App Proxy requests do not provide an id token. Customer Account and If you require access to the Shopify Admin GraphQL API during these requests you must load an offline access token that was exchanged from an App Home, Admin UI or POS UI Extension request. +In every case below, use `$result->shop` to look up the stored token. Do not parse the shop yourself (see [Getting the shop](#getting-the-shop)). + #### Webhooks ```php @@ -677,12 +803,12 @@ function webhookHandler($request) $req = requestToShopifyReq($request); $result = $shopify->verifyWebhookReq($req); - if (!$result['ok']) { + if (!$result->ok) { return shopifyResultToResponse($result); } // Your database logic here - $accessToken = getAccessToken($result['shop'], 'offline'); + $accessToken = getAccessToken($result->shop, 'offline'); } ``` @@ -692,10 +818,10 @@ App proxy is very similar to webhooks: ```php $result = $shopify->verifyAppProxyReq($req); -$loggedInCustomerId = $result['loggedInCustomerId']; +$loggedInCustomerId = $result->loggedInCustomerId; ``` -If the customer is not logged in, the `loggedInCustomerId` will be `null`. Do not confuse this with a `userId` stored with an online token which are merchant IDs, not customer IDs. +If the customer is not logged in, the `loggedInCustomerId` will be `null`. Do not confuse this with a `userId` stored with an online token, which are merchant IDs, not customer IDs. #### Customer Account UI Extension @@ -721,10 +847,14 @@ Flow Action requests are almost identical to webhooks: $result = $shopify->verifyFlowActionReq($req); ``` -### Getting access tokens with Client Credentials +### Getting access tokens with client credentials [Client credentials exchange](https://shopify.dev/docs/apps/build/authentication-authorization/access-tokens/client-credentials-grant) allows you to obtain an access token using only your app's client ID and client secret, without requiring an ID token. This is designed for trusted, server-to-server integrations (for example, internal automation or back-office services). +**Do** use this for trusted server-to-server work where there is no merchant request. + +**Don't** use it to authenticate a request coming from App Home or an extension. Those requests carry an ID token, and you should verify them and exchange that token instead. + ```php function getOrRefreshAccessToken($shop) { @@ -732,36 +862,51 @@ function getOrRefreshAccessToken($shop) // Check if we have a valid token $existingToken = getAccessToken($shop); - if ($existingToken && !isExpired($existingToken['expires'])) { + if ($existingToken && !isExpired($existingToken->expires)) { return $existingToken; } // Get a new token using client credentials $result = $shopify->exchangeUsingClientCredentials(shop: $shop); - if (!$result['ok']) { + if (!$result->ok) { // Log the error - error_log("{$result['log']['code']} - {$result['log']['detail']}"); + error_log("{$result->log->code} - {$result->log->detail}"); return null; } // Save the new token - saveAccessToken($result['accessToken']); - return $result['accessToken']; + saveAccessToken($result->accessToken); + return $result->accessToken; } ``` The `accessToken` object contains: -| Property | Description | -| --------- | ------------------------------------------------------ | -| `shop` | The shop domain | -| `token` | The access token string | -| `scope` | The granted scopes | -| `expires` | ISO 8601 datetime when the token expires (24 hours) | +| Property | Description | +| ------------ | --------------------------------------------------- | +| `shop` | The shop sub domain (e.g., "test-shop") | +| `accessMode` | Always "offline" | +| `token` | The access token string | +| `scope` | The granted scopes | +| `expires` | ISO 8601 datetime when the token expires (24 hours) | +| `user` | Always `null` for client credentials | Note: Client credentials tokens expire after 24 hours and do not include a refresh token. When the token expires, request a new one using `exchangeUsingClientCredentials` with the same credentials. +## Common misuses to avoid + +The package already handles these for you. Rebuilding them yourself is slower, and in the security-sensitive cases it is genuinely risky. Use the built-in path. + +| Don't | Do instead | Why | +| --- | --- | --- | +| Parse the shop from the ID token or request | Use `$result->shop` | It is already parsed correctly per request type and verified against spoofing. The shop decides which store's token is used. | +| Build your own token-refresh page | Use `appHomePatchIdToken` | It returns a complete, safe response. Custom pages that render request values are a common injection risk. | +| Render App Home without the response headers | Return `$result->response->headers` | These are the required iframe-protection headers (for example CSP `frame-ancestors`). | +| Craft your own response on a failed verify | Return `$result->response` as-is | It has the correct status and the security headers already set. | +| Alter headers, query string, or body before verifying | Pass the raw request through unchanged | Verification depends on the exact bytes Shopify sent. | +| Add the ID token to the URL, or reach for a single-page app, to keep navigation authenticated | Wire the token-refresh route and pass `appHomePatchIdTokenPath` on every verify | Same-origin link and full-page navigations arrive without a session token. The route lets App Bridge re-request with a fresh one, so multi-page apps work without tokens in URLs. | + ## Contributing, issues, feedback and feature requests This package does not accept contributions, but we'd love to hear your feedback. diff --git a/composer.json b/composer.json index 2a8eb03..a50baed 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require": { "php": ">=8.2", "firebase/php-jwt": "^7.0", - "guzzlehttp/guzzle": "^7.0" + "guzzlehttp/guzzle": "^7.0 || ^8.0" }, "require-dev": { "squizlabs/php_codesniffer": "^3.13" diff --git a/src/Internal/Verify/AdminUIExt.php b/src/Internal/Verify/AdminUIExt.php index 76474f5..b5179a9 100644 --- a/src/Internal/Verify/AdminUIExt.php +++ b/src/Internal/Verify/AdminUIExt.php @@ -30,7 +30,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: 'Expected request.method to be a non-empty string', @@ -51,7 +51,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: 'Expected request.headers to be an object', @@ -72,7 +72,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: 'Expected request.url to be a non-empty string', @@ -103,7 +103,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'options_request', detail: 'OPTIONS request handled for CORS preflight. Respond 204 No Content using the provided response.', @@ -130,7 +130,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'missing_authorization_header', detail: 'Required `Authorization` header is missing. Respond 401 Unauthorized using the provided response.', @@ -152,7 +152,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'invalid_id_token', detail: 'ID token verification failed. Respond 401 Unauthorized using the provided response.', @@ -210,7 +210,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: $errorCode, detail: $detailMsg, @@ -234,7 +234,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'invalid_aud', detail: 'ID token audience (aud) claim does not match clientId. Respond 401 Unauthorized using the provided response.', @@ -266,7 +266,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable claims: $payload ), userId: $userId, - newIdTokenResponse: [ + invalidTokenResponse: [ 'status' => 401, 'body' => '', 'headers' => [ diff --git a/src/Internal/Verify/AppHomeReq.php b/src/Internal/Verify/AppHomeReq.php index bcd3e23..ba55c03 100644 --- a/src/Internal/Verify/AppHomeReq.php +++ b/src/Internal/Verify/AppHomeReq.php @@ -63,7 +63,7 @@ private static function buildPatchIdTokenRedirect(array $urlParts, string $path, shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'redirect_to_patch_id_token_page', detail: 'Embedded app without id_token. Redirect to the patch ID token page to obtain a new token using the provided response.', @@ -86,7 +86,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: 'Expected appHomePatchIdTokenPath to be a non-empty string', @@ -106,7 +106,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: "Expected appHomePatchIdTokenPath to be a non-empty string, but got ''", @@ -128,7 +128,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: 'Expected request.url to be a non-empty string', @@ -149,7 +149,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: 'Expected request.headers to be an object', @@ -201,7 +201,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'invalid_id_token', detail: 'ID token verification failed. Respond 401 Unauthorized using the provided response.', @@ -225,7 +225,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'missing_authorization_and_id_token', detail: 'Neither Authorization header nor id_token query parameter present. Respond 401 Unauthorized using the provided response.', @@ -280,7 +280,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: $errorCode, detail: $detailMsg, @@ -312,7 +312,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'invalid_aud', detail: 'ID token audience (aud) claim does not match clientId. Respond 401 Unauthorized using the provided response.', @@ -343,8 +343,8 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo ]; } - // Build newIdTokenResponse - $newIdTokenResponse = null; + // Build invalidTokenResponse + $invalidTokenResponse = null; if (!$hasAuthorizationHeader) { // Document request - build patch ID token URL $cleanQuery = self::removeQueryParam($query, 'id_token'); @@ -355,7 +355,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo $patchIdTokenLocation = $urlParts['scheme'] . '://' . $urlParts['host'] . $appHomePatchIdTokenPath . '?' . $patchIdTokenQuery; - $newIdTokenResponse = [ + $invalidTokenResponse = [ 'status' => 302, 'body' => '', 'headers' => [ @@ -364,7 +364,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo ]; } else { // Fetch request - $newIdTokenResponse = [ + $invalidTokenResponse = [ 'status' => 401, 'body' => '', 'headers' => [ @@ -382,7 +382,7 @@ public static function verify(array $req, array $config, mixed $appHomePatchIdTo claims: $payload ), userId: $userId, - newIdTokenResponse: $newIdTokenResponse, + invalidTokenResponse: $invalidTokenResponse, log: new LogWithReq( code: 'verified', detail: 'App Home request verified. Proceed with business logic.' . (!$hasAuthorizationHeader ? ' Include the headers in the provided response.' : ''), diff --git a/src/Internal/Verify/NonExchangeableIdToken.php b/src/Internal/Verify/NonExchangeableIdToken.php index d5fb550..3a4b475 100644 --- a/src/Internal/Verify/NonExchangeableIdToken.php +++ b/src/Internal/Verify/NonExchangeableIdToken.php @@ -215,7 +215,7 @@ public static function verify(array $req, array $config, string $requestType): R // Extract shop from dest claim $dest = $payload['dest'] ?? ''; - $shop = str_replace('.myshopify.com', '', $dest); + $shop = str_replace(['.myshopify.com', 'https://'], '', $dest); return new ResultWithNonExchangeableIdToken( ok: true, diff --git a/src/Internal/Verify/PosUIExt.php b/src/Internal/Verify/PosUIExt.php index ee697b8..de25645 100644 --- a/src/Internal/Verify/PosUIExt.php +++ b/src/Internal/Verify/PosUIExt.php @@ -30,7 +30,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: 'Expected request.method to be a non-empty string', @@ -51,7 +51,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: 'Expected request.headers to be an object', @@ -72,7 +72,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'configuration_error', detail: 'Expected request.url to be a non-empty string', @@ -103,7 +103,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'options_request', detail: 'OPTIONS request handled for CORS preflight. Respond 204 No Content using the provided response.', @@ -130,7 +130,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'missing_authorization_header', detail: 'Required `Authorization` header is missing. Respond 401 Unauthorized using the provided response.', @@ -152,7 +152,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'invalid_id_token', detail: 'ID token verification failed. Respond 401 Unauthorized using the provided response.', @@ -206,7 +206,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: $errorCode, detail: $detailMsg, @@ -228,7 +228,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable shop: null, idToken: null, userId: null, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'invalid_aud', detail: 'ID token audience (aud) claim does not match clientId. Respond 401 Unauthorized using the provided response.', @@ -261,7 +261,7 @@ public static function verify(array $req, array $config): ResultWithExchangeable claims: $payload ), userId: $userId, - newIdTokenResponse: null, + invalidTokenResponse: null, log: new LogWithReq( code: 'verified', detail: 'POS UI Extension request verified. Proceed with business logic.', diff --git a/src/Types/ResultWithExchangeableIdToken.php b/src/Types/ResultWithExchangeableIdToken.php index b9a4d58..0a3a3a9 100644 --- a/src/Types/ResultWithExchangeableIdToken.php +++ b/src/Types/ResultWithExchangeableIdToken.php @@ -15,7 +15,7 @@ public function __construct( public ?string $shop, public ?IdToken $idToken, public ?string $userId, - public ?array $newIdTokenResponse, + public ?array $invalidTokenResponse, public LogWithReq $log, public ResponseInfo $response, ) { diff --git a/src/Version.php b/src/Version.php index 9746818..ac65f9b 100644 --- a/src/Version.php +++ b/src/Version.php @@ -4,4 +4,4 @@ namespace Shopify\App; -const VERSION = '0.1.5'; +const VERSION = '1.0.0';