Class: Portage::Ucp::Etsy::AccessTokenFetcher
- Inherits:
-
Object
- Object
- Portage::Ucp::Etsy::AccessTokenFetcher
- Includes:
- Support::TokenExchange
- Defined in:
- lib/portage/ucp/etsy/access_token_fetcher.rb
Overview
Exchanges a refresh_token for a new access_token via Etsy's OAuth2
/v3/public/oauth/token endpoint.
Doesn't handle the initial authorization-code exchange (that needs
a PKCE code_verifier from an interactive consent redirect, which is
a one-time setup step outside this gem's scope) — only the refresh
step a long-running server needs repeatedly. Unlike Shopify/Wix/
Magento, Etsy rotates the refresh_token on every use: the
response's refresh_token is a new value, and the one passed in
becomes invalid immediately, so callers must persist the returned
one before the next refresh, not just the access_token.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- ENDPOINT =
"https://api.etsy.com/v3/public/oauth/token".freeze
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(client_id:, refresh_token:) ⇒ AccessTokenFetcher
constructor
A new instance of AccessTokenFetcher.
Constructor Details
#initialize(client_id:, refresh_token:) ⇒ AccessTokenFetcher
Returns a new instance of AccessTokenFetcher.
25 26 27 28 |
# File 'lib/portage/ucp/etsy/access_token_fetcher.rb', line 25 def initialize(client_id:, refresh_token:) @client_id = client_id @refresh_token = refresh_token end |
Instance Method Details
#fetch ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/portage/ucp/etsy/access_token_fetcher.rb', line 30 def fetch body = exchange(ENDPOINT, { grant_type: "refresh_token", client_id: @client_id, refresh_token: @refresh_token }, error_class: Portage::Ucp::Etsy::Error, description: "token refresh failed") Result.new(access_token: body["access_token"], refresh_token: body["refresh_token"], expires_in: body["expires_in"]) end |