Skip to content

Commit

Permalink
Rename concern to TokenExchange
Browse files Browse the repository at this point in the history
  • Loading branch information
zzooeeyy committed Mar 25, 2024
1 parent bcc2e1e commit 4fbe18c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/shopify_app/ensure_has_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module ShopifyApp
module RetrieveSessionFromTokenExchange
module TokenExchange
extend ActiveSupport::Concern

def activate_shopify_session
Expand All @@ -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

Expand Down Expand Up @@ -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 ?
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 4fbe18c

Please sign in to comment.