Module: ShopifyApp::TokenExchange
- Extended by:
- ActiveSupport::Concern
- Includes:
- AdminAPI::WithTokenRefetch, EmbeddedApp, SanitizedParams
- Defined in:
- lib/shopify_app/controller_concerns/token_exchange.rb
Constant Summary collapse
- INVALID_SHOPIFY_ID_TOKEN_ERRORS =
[ ShopifyAPI::Errors::MissingJwtTokenError, ShopifyAPI::Errors::InvalidJwtTokenError, ].freeze
Instance Method Summary collapse
- #activate_shopify_session(&block) ⇒ Object
- #current_shopify_domain ⇒ Object
- #current_shopify_session ⇒ Object
- #current_shopify_session_id ⇒ Object
- #should_exchange_expired_token? ⇒ Boolean
Methods included from AdminAPI::WithTokenRefetch
Instance Method Details
#activate_shopify_session(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 19 def activate_shopify_session(&block) retrieve_session_from_token_exchange if current_shopify_session.blank? || should_exchange_expired_token? ShopifyApp::Logger.debug("Activating Shopify session") ShopifyAPI::Context.activate_session(current_shopify_session) with_token_refetch(current_shopify_session, shopify_id_token, &block) rescue *INVALID_SHOPIFY_ID_TOKEN_ERRORS => e ShopifyApp::Logger.debug("Responding to invalid Shopify ID token: #{e.}") respond_to_invalid_shopify_id_token unless performed? ensure ShopifyApp::Logger.debug("Deactivating session") ShopifyAPI::Context.deactivate_session end |
#current_shopify_domain ⇒ Object
50 51 52 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 50 def current_shopify_domain sanitized_shop_name || current_shopify_session&.shop end |
#current_shopify_session ⇒ Object
37 38 39 40 41 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 37 def current_shopify_session return unless current_shopify_session_id @current_shopify_session ||= ShopifyApp::SessionRepository.load_session(current_shopify_session_id) end |
#current_shopify_session_id ⇒ Object
43 44 45 46 47 48 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 43 def current_shopify_session_id @current_shopify_session_id ||= ShopifyAPI::Utils::SessionUtils.session_id_from_shopify_id_token( id_token: shopify_id_token, online: online_token_configured?, ) end |
#should_exchange_expired_token? ⇒ Boolean
33 34 35 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 33 def should_exchange_expired_token? ShopifyApp.configuration.check_session_expiry_date && current_shopify_session.expired? end |