Sha256: 3cd4dd10012c055be773490faf742a49e807a97eb4842ff6f3948cb388c64873

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module ShopifyApp
  # Cookie management helpers required for ITP implementation
  module Itp
    private

    def set_test_cookie
      return unless ShopifyApp.configuration.embedded_app?
      return unless user_agent_can_partition_cookies

      session['shopify.cookies_persist'] = true
    end

    def set_top_level_oauth_cookie
      session['shopify.top_level_oauth'] = true
    end

    def clear_top_level_oauth_cookie
      session.delete('shopify.top_level_oauth')
    end

    def user_agent_is_mobile
      user_agent = BrowserSniffer.new(request.user_agent).browser_info

      user_agent[:name].match(/Shopify\sMobile/)
    end

    def user_agent_is_pos
      user_agent = BrowserSniffer.new(request.user_agent).browser_info

      user_agent[:name].match(/Shopify\sPOS/)
    end

    def user_agent_can_partition_cookies
      user_agent = BrowserSniffer.new(request.user_agent).browser_info

      is_safari = user_agent[:name].match(/Safari/)

      return false unless is_safari

      user_agent[:version].match(/12.0/)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shopify_app-8.4.0 lib/shopify_app/controller_concerns/itp.rb