Skip to content
This repository was archived by the owner on Jan 7, 2019. It is now read-only.

Add respond_to? checks so it can work with API controllers #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions app/controllers/stormpath/rails/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ class BaseController < ApplicationController
include Stormpath::Rails::Controller

before_action :setup_accept_header
skip_before_action :verify_authenticity_token, if: :api_request?
skip_before_action :verify_authenticity_token, if: :in_development?
if respond_to?(:verify_authenticity_token)
skip_before_action :verify_authenticity_token, if: :api_request?
skip_before_action :verify_authenticity_token, if: :in_development?
end

layout 'stormpath/rails/layouts/stormpath'
if respond_to?(:layout)
layout 'stormpath/rails/layouts/stormpath'
end

private

Expand Down Expand Up @@ -54,14 +58,18 @@ def current_organization_name_key
nil
end
end
helper_method :current_organization_name_key
if respond_to?(:helper_method)
helper_method :current_organization_name_key
end

def social_auth
@social_auth ||= SocialLoginUrlBuilder.call(
req.base_url, organization_name_key: current_organization_name_key
)
end
helper_method :social_auth
if respond_to?(:helper_method)
helper_method :social_auth
end

def req
request
Expand Down
7 changes: 7 additions & 0 deletions lib/stormpath/rails/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ module Controller

def current_account
@current_account ||= begin
cookies =
if respond_to?(:cookies)
cookies
else
{}
end

ControllerAuthentication.new(cookies, request.headers['Authorization']).authenticate!
rescue ControllerAuthentication::UnauthenticatedRequest, Stormpath::Error, JWT::DecodeError
nil
Expand Down
4 changes: 3 additions & 1 deletion lib/stormpath/rails/social.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module Social
extend ActiveSupport::Concern

included do
helper_method :social_providers_present?
if respond_to?(:helper_method)
helper_method :social_providers_present?
end
end

private
Expand Down