-
-
Notifications
You must be signed in to change notification settings - Fork 970
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #348 from ryanwood/master
Add WePay strategy
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
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 |
This file contains 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
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 |