Look up the OAuth values on Devise instead of ENV.

This commit is contained in:
Akinori MUSHA 2014-09-30 14:42:36 +09:00
parent f0086f0466
commit dc8e8a0eeb
3 changed files with 6 additions and 12 deletions

View file

@ -20,11 +20,11 @@ module TwitterConcern
end
def twitter_consumer_key
ENV['TWITTER_OAUTH_KEY']
(config = Devise.omniauth_configs[:twitter]) && config.strategy.consumer_key
end
def twitter_consumer_secret
ENV['TWITTER_OAUTH_SECRET']
(config = Devise.omniauth_configs[:twitter]) && config.strategy.consumer_secret
end
def twitter_oauth_token

View file

@ -27,7 +27,7 @@ class ApplicationController < ActionController::Base
private
def twitter_oauth_check
if ENV['TWITTER_OAUTH_KEY'].blank? || ENV['TWITTER_OAUTH_SECRET'].blank?
unless Devise.omniauth_providers.include?(:twitter)
if @twitter_agent = current_user.agents.where("type like 'Agents::Twitter%'").first
@twitter_oauth_key = @twitter_agent.options['consumer_key'].presence || @twitter_agent.credential('twitter_consumer_key')
@twitter_oauth_secret = @twitter_agent.options['consumer_secret'].presence || @twitter_agent.credential('twitter_consumer_secret')
@ -36,7 +36,7 @@ class ApplicationController < ActionController::Base
end
def basecamp_auth_check
if ENV['THIRTY_SEVEN_SIGNALS_OAUTH_KEY'].blank? || ENV['THIRTY_SEVEN_SIGNALS_OAUTH_SECRET'].blank?
unless Devise.omniauth_providers.include?(:'37signals')
@basecamp_agent = current_user.agents.where(type: 'Agents::BasecampAgent').first
end
end

View file

@ -1,6 +1,4 @@
class Service < ActiveRecord::Base
PROVIDER_TO_ENV_MAP = {'37signals' => 'THIRTY_SEVEN_SIGNALS'}
attr_accessible :provider, :name, :token, :secret, :refresh_token, :expires_at, :global, :options, :uid
serialize :options, Hash
@ -51,16 +49,12 @@ class Service < ActiveRecord::Base
URI.join(client_options['site'], client_options['token_url'])
end
def provider_to_env
PROVIDER_TO_ENV_MAP[provider].presence || provider.upcase
end
def oauth_key
ENV["#{provider_to_env}_OAUTH_KEY"]
(config = Devise.omniauth_configs[provider.to_sym]) && config.args[0]
end
def oauth_secret
ENV["#{provider_to_env}_OAUTH_SECRET"]
(config = Devise.omniauth_configs[provider.to_sym]) && config.args[1]
end
def self.provider_specific_options(omniauth)