Skip to content

Commit

Permalink
Merge pull request #348 from ryanwood/master
Browse files Browse the repository at this point in the history
Add WePay strategy
  • Loading branch information
sferik committed May 28, 2011
2 parents 21e6ef8 + 0356c46 commit d14c053
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ OmniAuth currently supports the following external providers:
* Twitter (credit: [mbleigh](https://github.com/mbleigh))
* Vimeo (credit: [jamiew](https://github.com/jamiew))
* Vkontakte (credit: [german](https://github.com/german))
* WePay (credit: [ryanwood](https://github.com/ryanwood))
* Yammer (credit: [kltcalamay](https://github.com/kltcalamay))
* YouTube (credit: [jamiew](https://github.com/jamiew))
* CAS (Central Authentication Service) (credit: [jamesarosen](https://github.com/jamesarosen))
Expand Down
1 change: 1 addition & 0 deletions oa-oauth/lib/omniauth/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module Strategies
autoload :TypePad, 'omniauth/strategies/type_pad'
autoload :Vimeo, 'omniauth/strategies/vimeo'
autoload :Vkontakte, 'omniauth/strategies/vkontakte'
autoload :WePay, 'omniauth/strategies/we_pay'
autoload :Yahoo, 'omniauth/strategies/yahoo'
autoload :Yammer, 'omniauth/strategies/yammer'
autoload :YouTube, 'omniauth/strategies/you_tube'
Expand Down
48 changes: 48 additions & 0 deletions oa-oauth/lib/omniauth/strategies/we_pay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
module Strategies
# OAuth 2.0 based authentication with WePay. In order to
# sign up for an application, you need to [register an application](https://wepay.com/developer/register)
# and provide the proper credentials to this middleware.
class WePay < OAuth2
# @param [Rack Application] app standard middleware application argument
# @param [String] client_id the application ID for your client
# @param [String] client_secret the application secret
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
client_options = {
:site => "https://wepayapi.com",
:authorize_url => 'https://www.wepay.com/session/authorize',
:access_token_path => '/v1/oauth2/token'
}

super(app, :we_pay, client_id, client_secret, client_options, options, &block)
end

protected

def user_data
@data ||= MultiJson.decode(@access_token.get('/v1/user'))['result']
end

def user_info
{
'email' => user_data['email'],
'name' => "#{user_data['firstName']} #{user_data['lastName']}",
'first_name' => user_data['firstName'],
'last_name' => user_data['lastName'],
'image' => user_data['picture']
}
end

def auth_hash
OmniAuth::Utils.deep_merge(super, {
'uid' => user_data['user_id'],
'user_info' => user_info,
'extra' => {'user_hash' => user_data}
})
end
end
end
end
5 changes: 5 additions & 0 deletions oa-oauth/spec/omniauth/strategies/we_pay_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe OmniAuth::Strategies::WePay do
it_should_behave_like "an oauth2 strategy"
end

0 comments on commit d14c053

Please sign in to comment.