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
- #authenticated_shopify_domain ⇒ Object
- #current_shopify_domain ⇒ Object
- #current_shopify_session ⇒ Object
- #current_shopify_session_id ⇒ Object
- #requested_shopify_domain ⇒ 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 32 |
# 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? return if reject_mismatched_requested_shopify_domain 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 respond_to_invalid_shopify_id_token(e) ensure ShopifyApp::Logger.debug("Deactivating session") ShopifyAPI::Context.deactivate_session end |
#authenticated_shopify_domain ⇒ Object
55 56 57 58 59 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 55 def authenticated_shopify_domain authenticated_shopify_domain_from_token rescue *INVALID_SHOPIFY_ID_TOKEN_ERRORS => e respond_to_invalid_shopify_id_token(e) end |
#current_shopify_domain ⇒ Object
61 62 63 64 65 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 61 def current_shopify_domain authenticated_shopify_domain_from_token rescue *INVALID_SHOPIFY_ID_TOKEN_ERRORS => e respond_to_invalid_shopify_id_token(e) end |
#current_shopify_session ⇒ Object
38 39 40 41 42 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 38 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
44 45 46 47 48 49 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 44 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 |
#requested_shopify_domain ⇒ Object
51 52 53 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 51 def requested_shopify_domain sanitized_shop_name end |
#should_exchange_expired_token? ⇒ Boolean
34 35 36 |
# File 'lib/shopify_app/controller_concerns/token_exchange.rb', line 34 def should_exchange_expired_token? ShopifyApp.configuration.check_session_expiry_date && current_shopify_session.expired? end |