Created
May 31, 2012 01:57
-
-
Save coderforhire/2840364 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config/initiliazers/omniauth.rb | |
require 'stripedotcom' | |
# Set the default hostname for omniauth to send callbacks to. | |
# seems to be a bug in omniauth that it drops the httpS | |
# this still exists in 0.2.0 | |
# note: you will have to change this url to your Heroku app url when you deploy it to Heroku. | |
OmniAuth.config.full_host = 'http://localhost:3000' | |
module OmniAuth | |
module Strategies | |
#tell omniauth to load our strategy | |
autoload :Stripedotcom, 'lib/stripedotcom' | |
end | |
end | |
Rails.application.config.middleware.use OmniAuth::Builder do | |
provider :stripedotcom, 'CLIENTID', 'SECRETKEY' #, 'test' | |
end | |
lib/stripedotcom.rb | |
require 'multi_json' | |
module OmniAuth | |
module Strategies | |
class Stripedotcom < OAuth2 | |
def initialize(app, client_id, client_secret, options = {}, &block) | |
client_options = { | |
:site => "https://manage.stripe.com", | |
:authorize_path => "https://manage.stripe.com/oauth/authorize", | |
:access_token_path => "https://manage.stripe.com/oauth/token" | |
} | |
super(app, :stripedotcom, client_id, client_secret, client_options ) | |
end | |
def request_phase | |
options[:response_type] ||= 'code' | |
super | |
end | |
def callback_phase | |
options[:grant_type] ||= 'authorization_code' | |
super | |
end | |
def auth_hash | |
OmniAuth::Utils.deep_merge(super, { | |
'instance_url' => @access_token['instance_url'] | |
}) | |
end | |
end | |
end | |
end | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment