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
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
4
4
## Unreleased
5
5
6
6
- Add support for expiring offline access tokens with refresh tokens. See [OAuth documentation](docs/usage/oauth.md#expiring-offline-access-tokens) for details.
7
+
- 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.
-[Migrating Non-Expiring Tokens to Expiring Tokens](#migrating-non-expiring-tokens-to-expiring-tokens)
19
20
-[Using OAuth Session to make authenticated API calls](#using-oauth-session-to-make-authenticated-api-calls)
20
21
21
22
## Session Persistence
@@ -387,6 +388,51 @@ if session.refresh_token_expired?
387
388
end
388
389
```
389
390
391
+
### Migrating Non-Expiring Tokens to Expiring Tokens
392
+
393
+
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.
394
+
395
+
> [!WARNING]
396
+
> 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.
|`non_expiring_offline_session`|`ShopifyAPI::Auth::Session`| Yes | A Session object containing 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:
424
+
425
+
1.**Update your database schema** to add `expires_at` (timestamp), `refresh_token` (string) and `refresh_token_expires` (timestamp) columns to your session storage
426
+
2.**Implement refresh logic** in your app to handle token expiration using `ShopifyAPI::Auth::RefreshToken.refresh_access_token`
427
+
3.**Enable expiring tokens in your Context setup** so new installations will request and receive expiring tokens:
428
+
```ruby
429
+
ShopifyAPI::Context.setup(
430
+
expiring_offline_access_tokens:true,
431
+
# ... other config
432
+
)
433
+
```
434
+
4.**Migrate existing non-expiring tokens** for shops that have already installed your app using the migration method above
435
+
390
436
## Using OAuth Session to make authenticated API calls
391
437
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