You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,9 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
5
5
- ⚠️ [Breaking] Minimum required Ruby version is now 3.2. Ruby 3.0 and 3.1 are no longer supported.
6
6
- ⚠️ [Breaking] Removed `Session#serialize` and `Session.deserialize` methods due to security concerns (RCE vulnerability via `Oj.load`). These methods were not used internally by the library. If your application relies on session serialization, use `Session.new()` to reconstruct sessions from stored attributes instead.
7
7
8
+
- Add support for expiring offline access tokens with refresh tokens. See [OAuth documentation](docs/usage/oauth.md#expiring-offline-access-tokens) for details.
9
+
- Add `ShopifyAPI::Auth::TokenExchange.migrate_to_expiring_token` method to migrate existing non-expiring offline tokens to expiring tokens. See [migration documentation](docs/usage/oauth.md#migrating-non-expiring-tokens-to-expiring-tokens) for details.
10
+
8
11
### 15.0.0
9
12
10
13
- ⚠️ [Breaking] Removed deprecated `ShopifyAPI::Webhooks::Handler` interface. Apps must migrate to `ShopifyAPI::Webhooks::WebhookHandler` which provides `webhook_id` and `api_version` in addition to `topic`, `shop`, and `body`. See [BREAKING_CHANGES_FOR_V15.md](BREAKING_CHANGES_FOR_V15.md) for migration guide.
-**Authorization Code Grant**: The OAuth flow will request expiring offline access tokens by sending `expiring: 1` parameter
329
+
-**Token Exchange**: When requesting offline access tokens via token exchange, the flow will request expiring tokens
330
+
331
+
The resulting `Session` object will contain:
332
+
-`access_token`: The access token that will eventually expire
333
+
-`expires`: The expiration time for the access token
334
+
-`refresh_token`: A token that can be used to refresh the access token
335
+
-`refresh_token_expires`: The expiration time for the refresh token
336
+
337
+
### Refreshing Access Tokens
338
+
339
+
When your access token expires, you can use the refresh token to obtain a new access token using the `ShopifyAPI::Auth::RefreshToken.refresh_access_token` method.
|`shop`|`String`| Yes | A Shopify domain name in the form `{exampleshop}.myshopify.com`. |
345
+
|`refresh_token`|`String`| Yes | The refresh token from the session. |
346
+
347
+
#### Output
348
+
This method returns a new `ShopifyAPI::Auth::Session` object with a fresh access token and a new refresh token. Your app should store this new session to replace the expired one.
349
+
350
+
#### Example
351
+
```ruby
352
+
defrefresh_session(shop, refresh_token)
353
+
begin
354
+
# Refresh the access token using the refresh token
# Refresh token has expired, need to re-authenticate with OAuth
387
+
end
388
+
```
389
+
390
+
### Migrating Non-Expiring Tokens to Expiring Tokens
391
+
392
+
If you have existing non-expiring offline access tokens and want to migrate them to expiring tokens, you can use the `ShopifyAPI::Auth::TokenExchange.migrate_to_expiring_token` method. This performs a token exchange that converts your non-expiring offline token into an expiring one with a refresh token.
393
+
394
+
> [!WARNING]
395
+
> This is a **one-time, irreversible migration** per shop. Once you migrate a shop's token to an expiring token, you cannot convert it back to a non-expiring token. The shop would need to reinstall your app with `expiring_offline_access_tokens: false` in your Context configuration to obtain a new non-expiring token.
|`shop`|`String`| Yes | A Shopify domain name in the form `{exampleshop}.myshopify.com`. |
401
+
|`non_expiring_offline_token`|`String`| Yes | The non-expiring offline access token to migrate. |
402
+
403
+
#### Output
404
+
This method returns a new `ShopifyAPI::Auth::Session` object with an expiring access token and refresh token. Your app should store this new session to replace the non-expiring one.
When migrating your app to use expiring tokens, follow this order:
425
+
426
+
1.**Update your database schema** to add `expires_at` (timestamp), `refresh_token` (string) and `refresh_token_expires` (timestamp) columns to your session storage
427
+
2.**Implement refresh logic** in your app to handle token expiration using `ShopifyAPI::Auth::RefreshToken.refresh_access_token`
428
+
3.**Enable expiring tokens in your Context setup** so new installations will request and receive expiring tokens:
429
+
```ruby
430
+
ShopifyAPI::Context.setup(
431
+
expiring_offline_access_tokens:true,
432
+
# ... other config
433
+
)
434
+
```
435
+
4.**Migrate existing non-expiring tokens** for shops that have already installed your app using the migration method above
436
+
308
437
## Using OAuth Session to make authenticated API calls
309
438
Once your OAuth flow is complete, and you have persisted your `Session` object, you may use that `Session` object to make authenticated API calls.
0 commit comments