Class: ShopifyApp::CallbackController

Inherits:
ActionController::Base
  • Object
show all
Includes:
EnsureBilling, LoginProtection
Defined in:
app/controllers/shopify_app/callback_controller.rb

Overview

Performs login after OAuth completes

Constant Summary

Constants included from EnsureBilling

EnsureBilling::RECURRING_INTERVALS

Constants included from LoginProtection

LoginProtection::ACCESS_TOKEN_REQUIRED_HEADER

Instance Method Summary collapse

Methods included from LoginProtection

#activate_shopify_session, #add_top_level_redirection_headers, #current_shopify_session, #jwt_expire_at, #login_again_if_different_user_or_shop, #signal_access_token_required

Instance Method Details

#callbackObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/shopify_app/callback_controller.rb', line 9

def callback
  begin
    filtered_params = request.parameters.symbolize_keys.slice(:code, :shop, :timestamp, :state, :host, :hmac)

    auth_result = ShopifyAPI::Auth::Oauth.validate_auth_callback(
      cookies: {
        ShopifyAPI::Auth::Oauth::SessionCookie::SESSION_COOKIE_NAME =>
          cookies.encrypted[ShopifyAPI::Auth::Oauth::SessionCookie::SESSION_COOKIE_NAME],
      },
      auth_query: ShopifyAPI::Auth::Oauth::AuthQuery.new(**filtered_params),
    )
  rescue
    return respond_with_error
  end

  cookies.encrypted[auth_result[:cookie].name] = {
    expires: auth_result[:cookie].expires,
    secure: true,
    http_only: true,
    value: auth_result[:cookie].value,
  }

  session[:shopify_user_id] = auth_result[:session].associated_user.id if auth_result[:session].online?

  if start_user_token_flow?(auth_result[:session])
    return respond_with_user_token_flow
  end

  perform_post_authenticate_jobs(auth_result[:session])
  has_payment = check_billing(auth_result[:session])

  respond_successfully if has_payment
end