Sha256: 0b51583d3533fc4bcaa6462a03141128eebcaf4dc25db6533ef7d1549e35d636

Contents?: true

Size: 944 Bytes

Versions: 2

Compression:

Stored size: 944 Bytes

Contents

# frozen_string_literal: true

module ShopifyApp
  module WithShopifyIdToken
    extend ActiveSupport::Concern

    def shopify_id_token
      @shopify_id_token ||= id_token_from_request_env || id_token_from_authorization_header || id_token_from_url_param
    end

    def jwt_shopify_domain
      request.env["jwt.shopify_domain"]
    end

    def jwt_shopify_user_id
      request.env["jwt.shopify_user_id"]
    end

    def jwt_expire_at
      expire_at = request.env["jwt.expire_at"]
      return unless expire_at

      expire_at - 5.seconds # 5s gap to start fetching new token in advance
    end

    private

    def id_token_from_request_env
      # This is set from ShopifyApp::JWTMiddleware
      request.env["jwt.token"]
    end

    def id_token_from_authorization_header
      request.headers["HTTP_AUTHORIZATION"]&.match(/^Bearer (.+)$/)&.[](1)
    end

    def id_token_from_url_param
      params["id_token"]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shopify_app-22.2.1 lib/shopify_app/controller_concerns/with_shopify_id_token.rb
shopify_app-22.2.0 lib/shopify_app/controller_concerns/with_shopify_id_token.rb