diff --git a/app/controllers/concerns/shopify_app/ensure_has_session.rb b/app/controllers/concerns/shopify_app/ensure_has_session.rb index 740ab1efe..cc0f3067a 100644 --- a/app/controllers/concerns/shopify_app/ensure_has_session.rb +++ b/app/controllers/concerns/shopify_app/ensure_has_session.rb @@ -8,7 +8,7 @@ module EnsureHasSession include ShopifyApp::Localization if ShopifyApp.configuration.use_new_embedded_auth_strategy? - include ShopifyApp::RetrieveSessionFromTokenExchange + include ShopifyApp::TokenExchange around_action :activate_shopify_session else include ShopifyApp::LoginProtection diff --git a/lib/shopify_app.rb b/lib/shopify_app.rb index 5ed841e48..2f109ec00 100644 --- a/lib/shopify_app.rb +++ b/lib/shopify_app.rb @@ -52,7 +52,7 @@ def self.use_webpacker? require "shopify_app/controller_concerns/payload_verification" require "shopify_app/controller_concerns/app_proxy_verification" require "shopify_app/controller_concerns/webhook_verification" - require "shopify_app/controller_concerns/retrieve_session_from_token_exchange" + require "shopify_app/controller_concerns/token_exchange" # jobs require "shopify_app/jobs/webhooks_manager_job" diff --git a/lib/shopify_app/controller_concerns/retrieve_session_from_token_exchange.rb b/lib/shopify_app/controller_concerns/token_exchange.rb similarity index 93% rename from lib/shopify_app/controller_concerns/retrieve_session_from_token_exchange.rb rename to lib/shopify_app/controller_concerns/token_exchange.rb index b10423b5c..86a506f4c 100644 --- a/lib/shopify_app/controller_concerns/retrieve_session_from_token_exchange.rb +++ b/lib/shopify_app/controller_concerns/token_exchange.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module ShopifyApp - module RetrieveSessionFromTokenExchange + module TokenExchange extend ActiveSupport::Concern def activate_shopify_session @@ -28,7 +28,7 @@ def current_shopify_session session_id = ShopifyAPI::Utils::SessionUtils.current_session_id( request.headers["HTTP_AUTHORIZATION"], nil, - ShopifyApp.configuration.online_token_configured?, + online_token_configured?, ) return nil unless session_id @@ -57,7 +57,7 @@ def retrieve_session_from_token_exchange requested_token_type: ShopifyAPI::Auth::TokenExchange::RequestedTokenType::OFFLINE_ACCESS_TOKEN, ) - if session && ShopifyApp.configuration.online_token_configured? + if session && online_token_configured? ShopifyApp::Logger.info("Performing Token Exchange for [#{domain}] - (Online)") exchange_token( shop: domain, # TODO: use jwt_shopify_domain ? @@ -86,12 +86,12 @@ def exchange_token(shop:, session_token:, requested_token_type:) # respond_to_invalid_session_token return rescue ShopifyAPI::Errors::HttpResponseError => error - ShopifyApp::Logger.info( + ShopifyApp::Logger.error( "A #{error.code} error (#{error.class}) occurred during the token exchange. Response: #{error.response.body}", ) raise rescue => error - ShopifyApp::Logger.info("An error occurred during the token exchange: #{error.message}") + ShopifyApp::Logger.error("An error occurred during the token exchange: #{error.message}") raise end @@ -133,5 +133,9 @@ def respond_to_invalid_session_token # redirect_to("#{patch_session_token_url}?#{patch_session_token_params.to_query}", allow_other_host: true) # end end + + def online_token_configured? + ShopifyApp.configuration.online_token_configured? + end end end