oa-oauth 0.1.6 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.rspec +3 -0
- data/.yardopts +4 -0
- data/{LICENSE.rdoc → LICENSE} +2 -2
- data/README.rdoc +1 -1
- data/Rakefile +6 -0
- data/autotest/discover.rb +1 -0
- data/lib/oa-oauth.rb +1 -0
- data/lib/omniauth/oauth.rb +39 -7
- data/lib/omniauth/strategies/bitly.rb +46 -0
- data/lib/omniauth/strategies/dailymile.rb +64 -0
- data/lib/omniauth/strategies/doit.rb +60 -0
- data/lib/omniauth/strategies/dopplr.rb +38 -7
- data/lib/omniauth/strategies/douban.rb +60 -0
- data/lib/omniauth/strategies/evernote.rb +54 -0
- data/lib/omniauth/strategies/facebook.rb +29 -11
- data/lib/omniauth/strategies/foursquare.rb +50 -27
- data/lib/omniauth/strategies/github.rb +15 -12
- data/lib/omniauth/strategies/goodreads.rb +44 -0
- data/lib/omniauth/strategies/google.rb +80 -0
- data/lib/omniauth/strategies/gowalla.rb +13 -10
- data/lib/omniauth/strategies/hyves.rb +67 -0
- data/lib/omniauth/strategies/identica.rb +4 -4
- data/lib/omniauth/strategies/instagram.rb +56 -0
- data/lib/omniauth/strategies/instapaper.rb +40 -0
- data/lib/omniauth/strategies/linked_in.rb +24 -15
- data/lib/omniauth/strategies/meetup.rb +40 -7
- data/lib/omniauth/strategies/miso.rb +41 -0
- data/lib/omniauth/strategies/mixi.rb +59 -0
- data/lib/omniauth/strategies/netflix.rb +65 -0
- data/lib/omniauth/strategies/oauth.rb +51 -13
- data/lib/omniauth/strategies/oauth2.rb +48 -23
- data/lib/omniauth/strategies/qzone.rb +69 -0
- data/lib/omniauth/strategies/rdio.rb +45 -0
- data/lib/omniauth/strategies/renren.rb +87 -0
- data/lib/omniauth/strategies/salesforce.rb +44 -0
- data/lib/omniauth/strategies/smug_mug.rb +42 -0
- data/lib/omniauth/strategies/sound_cloud.rb +9 -9
- data/lib/omniauth/strategies/t163.rb +57 -0
- data/lib/omniauth/strategies/teambox.rb +49 -0
- data/lib/omniauth/strategies/thirty_seven_signals.rb +11 -8
- data/lib/omniauth/strategies/tqq.rb +64 -0
- data/lib/omniauth/strategies/trade_me.rb +45 -0
- data/lib/omniauth/strategies/trip_it.rb +3 -16
- data/lib/omniauth/strategies/tsina.rb +79 -0
- data/lib/omniauth/strategies/tsohu.rb +57 -0
- data/lib/omniauth/strategies/tumblr.rb +60 -0
- data/lib/omniauth/strategies/twitter.rb +21 -11
- data/lib/omniauth/strategies/type_pad.rb +76 -0
- data/lib/omniauth/strategies/vimeo.rb +54 -0
- data/lib/omniauth/strategies/vkontakte.rb +84 -0
- data/lib/omniauth/strategies/xauth.rb +67 -0
- data/lib/omniauth/strategies/yahoo.rb +55 -0
- data/lib/omniauth/strategies/yammer.rb +43 -0
- data/lib/omniauth/strategies/you_tube.rb +73 -0
- data/lib/omniauth/version.rb +19 -0
- data/oa-oauth.gemspec +33 -0
- data/spec/fixtures/basecamp_200.xml +24 -0
- data/spec/fixtures/campfire_200.json +10 -0
- data/spec/omniauth/strategies/bitly_spec.rb +5 -0
- data/spec/omniauth/strategies/dailymile_spec.rb +5 -0
- data/spec/omniauth/strategies/doit_spec.rb +5 -0
- data/spec/omniauth/strategies/dopplr_spec.rb +5 -0
- data/spec/omniauth/strategies/douban_spec.rb +5 -0
- data/spec/omniauth/strategies/evernote_spec.rb +5 -0
- data/spec/omniauth/strategies/facebook_spec.rb +5 -0
- data/spec/omniauth/strategies/foursquare_spec.rb +18 -0
- data/spec/omniauth/strategies/github_spec.rb +5 -0
- data/spec/omniauth/strategies/goodreads_spec.rb +6 -0
- data/spec/omniauth/strategies/google_spec.rb +5 -0
- data/spec/omniauth/strategies/gowalla_spec.rb +5 -0
- data/spec/omniauth/strategies/hyves_spec.rb +5 -0
- data/spec/omniauth/strategies/identica_spec.rb +5 -0
- data/spec/omniauth/strategies/linked_in_spec.rb +5 -0
- data/spec/omniauth/strategies/meetup_spec.rb +14 -0
- data/spec/omniauth/strategies/miso_spec.rb +5 -0
- data/spec/omniauth/strategies/netflix_spec.rb +5 -0
- data/spec/omniauth/strategies/oauth2_spec.rb +0 -0
- data/spec/omniauth/strategies/oauth_spec.rb +77 -0
- data/spec/omniauth/strategies/rdio_spec.rb +5 -0
- data/spec/omniauth/strategies/salesforce_spec.rb +5 -0
- data/spec/omniauth/strategies/smug_mug_spec.rb +5 -0
- data/spec/omniauth/strategies/sound_cloud_spec.rb +5 -0
- data/spec/omniauth/strategies/t163_spec.rb +5 -0
- data/spec/omniauth/strategies/teambox_spec.rb +5 -0
- data/spec/omniauth/strategies/thirty_seven_signals_spec.rb +5 -0
- data/spec/omniauth/strategies/trade_me_spec.rb +5 -0
- data/spec/omniauth/strategies/trip_it_spec.rb +5 -0
- data/spec/omniauth/strategies/tsina_spec.rb +5 -0
- data/spec/omniauth/strategies/tumblr_spec.rb +5 -0
- data/spec/omniauth/strategies/twitter_spec.rb +20 -0
- data/spec/omniauth/strategies/type_pad_spec.rb +5 -0
- data/spec/omniauth/strategies/vimeo_spec.rb +5 -0
- data/spec/omniauth/strategies/vkontakte_spec.rb +5 -0
- data/spec/omniauth/strategies/yahoo_spec.rb +5 -0
- data/spec/omniauth/strategies/yammer_spec.rb +5 -0
- data/spec/omniauth/strategies/you_tube_spec.rb +5 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/shared_examples.rb +29 -0
- metadata +231 -127
- data/CHANGELOG.rdoc +0 -5
@@ -12,61 +12,86 @@ module OmniAuth
|
|
12
12
|
# OAuth 2.0.
|
13
13
|
class OAuth2
|
14
14
|
include OmniAuth::Strategy
|
15
|
-
|
15
|
+
|
16
16
|
# The options passed in to the strategy.
|
17
17
|
attr_accessor :options
|
18
18
|
# The `OAuth2::Client` for this strategy.
|
19
|
-
attr_accessor :
|
20
|
-
|
19
|
+
attr_accessor :client_id, :client_secret, :client_options
|
20
|
+
|
21
21
|
# An error that is indicated in the OAuth 2.0 callback.
|
22
|
-
# This could be a `redirect_uri_mismatch` or other
|
22
|
+
# This could be a `redirect_uri_mismatch` or other
|
23
23
|
class CallbackError < StandardError
|
24
24
|
attr_accessor :error, :error_reason, :error_uri
|
25
|
-
|
25
|
+
|
26
26
|
def initialize(error, error_reason=nil, error_uri=nil)
|
27
27
|
self.error = error
|
28
28
|
self.error_reason = error_reason
|
29
29
|
self.error_uri = error_uri
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# Initialize a new OAuth 2.0 authentication provider.
|
34
|
-
|
34
|
+
|
35
35
|
# @param [Rack Application] app standard middleware application argument
|
36
36
|
# @param [String] name the name for this provider to be used in its URL, e.g. `/auth/name`
|
37
37
|
# @param [String] client_id the client/application ID of this provider
|
38
38
|
# @param [String] client_secret the client/application secret of this provider
|
39
39
|
# @param [Hash] options that will be passed through to the OAuth2::Client (see [oauth2 docs](http://rubydoc.info/gems/oauth2))
|
40
|
-
def initialize(app, name, client_id, client_secret, options = {})
|
41
|
-
|
42
|
-
self.
|
43
|
-
self.
|
40
|
+
def initialize(app, name, client_id = nil, client_secret = nil, client_options = {}, options = {}, &block)
|
41
|
+
self.client_id = client_id
|
42
|
+
self.client_secret = client_secret
|
43
|
+
self.client_options = client_options
|
44
|
+
super
|
44
45
|
end
|
45
|
-
|
46
|
+
|
47
|
+
def client
|
48
|
+
::OAuth2::Client.new(client_id, client_secret, client_options.merge(options[:client_options] || {}))
|
49
|
+
end
|
50
|
+
|
51
|
+
def callback_url
|
52
|
+
full_host + callback_path
|
53
|
+
end
|
54
|
+
|
46
55
|
protected
|
47
|
-
|
56
|
+
|
48
57
|
def request_phase
|
49
58
|
redirect client.web_server.authorize_url({:redirect_uri => callback_url}.merge(options))
|
50
59
|
end
|
51
|
-
|
60
|
+
|
52
61
|
def callback_phase
|
53
62
|
if request.params['error'] || request.params['error_reason']
|
54
63
|
raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
|
55
64
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
65
|
+
|
66
|
+
@access_token = build_access_token
|
67
|
+
|
68
|
+
if @access_token.expires? && @access_token.expires_in <= 0
|
69
|
+
client.request(:post, client.access_token_url, {
|
70
|
+
'client_id' => client_id,
|
71
|
+
'grant_type' => 'refresh_token',
|
72
|
+
'client_secret' => client_secret,
|
73
|
+
'refresh_token' => @access_token.refresh_token
|
74
|
+
}.merge(options))
|
75
|
+
@access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
|
76
|
+
end
|
77
|
+
|
59
78
|
super
|
60
79
|
rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
|
61
80
|
fail!(:invalid_credentials, e)
|
81
|
+
rescue ::MultiJson::DecodeError => e
|
82
|
+
fail!(:invalid_response, e)
|
62
83
|
end
|
63
|
-
|
84
|
+
|
85
|
+
def build_access_token
|
86
|
+
verifier = request.params['code']
|
87
|
+
client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
|
88
|
+
end
|
89
|
+
|
64
90
|
def auth_hash
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
})
|
91
|
+
credentials = {'token' => @access_token.token}
|
92
|
+
credentials.merge('refresh_token' => @access_token.refresh_token) if @access_token.expires?
|
93
|
+
|
94
|
+
OmniAuth::Utils.deep_merge(super, {'credentials' => credentials})
|
70
95
|
end
|
71
96
|
end
|
72
97
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to qzone (QQ) via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Qzone, 'consumerkey', 'consumersecret'
|
13
|
+
#
|
14
|
+
class Qzone < OmniAuth::Strategies::OAuth
|
15
|
+
# Initialize the middleware
|
16
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
17
|
+
client_options = {
|
18
|
+
:site => 'http://openapi.qzone.qq.com',
|
19
|
+
:request_token_path => '/oauth/qzoneoauth_request_token',
|
20
|
+
:access_token_path => '/oauth/qzoneoauth_access_token',
|
21
|
+
:authorize_path => '/oauth/qzoneoauth_authorize',
|
22
|
+
:scheme => :query_string,
|
23
|
+
:http_method => :get
|
24
|
+
}
|
25
|
+
|
26
|
+
options[:authorize_params] = {:oauth_consumer_key => consumer_key}
|
27
|
+
super(app, :qzone, consumer_key, consumer_secret, client_options, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
#HACK qzone is using a none-standard parameter oauth_overicode
|
31
|
+
def consumer_options
|
32
|
+
@consumer_options[:access_token_path] = '/oauth/qzoneoauth_access_token?oauth_vericode=' + request['oauth_vericode'] if request['oauth_vericode']
|
33
|
+
@consumer_options
|
34
|
+
end
|
35
|
+
|
36
|
+
def callback_phase
|
37
|
+
session['oauth'][name.to_s]['callback_confirmed'] = true
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def auth_hash
|
42
|
+
ui = user_info
|
43
|
+
OmniAuth::Utils.deep_merge(super, {
|
44
|
+
'uid' => ui['uid'],
|
45
|
+
'user_info' => ui,
|
46
|
+
'extra' => {'user_hash' => user_hash}
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
def user_info
|
51
|
+
user_hash = self.user_hash
|
52
|
+
{
|
53
|
+
'uid' => @access_token.params[:openid],
|
54
|
+
'nickname' => user_hash['nickname'],
|
55
|
+
'name' => user_hash['nickname'],
|
56
|
+
'image' => user_hash['figureurl'],
|
57
|
+
'urls' => {
|
58
|
+
'figureurl_1' => user_hash['figureurl_1'],
|
59
|
+
'figureurl_2' => user_hash['figureurl_2'],
|
60
|
+
}
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def user_hash
|
65
|
+
@user_hash ||= MultiJson.decode(@access_token.get("/user/get_user_info?format=json&openid=#{@access_token.params[:openid]}").body)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Rdio via OAuth and retrieve basic user information.
|
8
|
+
# Usage:
|
9
|
+
# use OmniAuth::Strategies::Rdio, 'consumerkey', 'consumersecret'
|
10
|
+
#
|
11
|
+
class Rdio < OmniAuth::Strategies::OAuth
|
12
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
13
|
+
opts = {
|
14
|
+
:site => 'http://api.rdio.com',
|
15
|
+
:request_token_path => "/oauth/request_token",
|
16
|
+
:access_token_path => "/oauth/access_token",
|
17
|
+
:authorize_url => "https://www.rdio.com/oauth/authorize"
|
18
|
+
}
|
19
|
+
super(app, :rdio, consumer_key, consumer_secret, opts, options, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def auth_hash
|
23
|
+
OmniAuth::Utils.deep_merge(super, {
|
24
|
+
'uid' => user_hash['key'],
|
25
|
+
'user_info' => user_info,
|
26
|
+
'extra' => { 'user_hash' => user_hash }
|
27
|
+
})
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_info
|
31
|
+
user = user_hash
|
32
|
+
{
|
33
|
+
'nickname' => user['username'],
|
34
|
+
'first_name' => user['firstName'],
|
35
|
+
'last_name' => user['lastName'],
|
36
|
+
'name' => "#{user['firstName']} #{user['lastName']}"
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def user_hash
|
41
|
+
@user_hash ||= MultiJson.decode(@access_token.post("http://api.rdio.com/1/", { :method => 'currentUser', :extras => 'username' }).body)['result']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Strategies
|
8
|
+
# Authenticate to Renren utilizing OAuth 2.0 and retrieve
|
9
|
+
# basic user information.
|
10
|
+
#
|
11
|
+
# @example Basic Usage
|
12
|
+
# use OmniAuth::Strategies::Renren, 'client_id', 'client_secret'
|
13
|
+
class Renren < OAuth2
|
14
|
+
# @param [Rack Application] app standard middleware application parameter
|
15
|
+
# @param [String] client_id the application id as [registered on Renren](http://dev.renren.com/)
|
16
|
+
# @param [String] client_secret the application secret as registered on Renren
|
17
|
+
# @option options [String] :scope ('publish_feed,status_update') comma-separated extended permissions such as `publish_feed` and `status_update`
|
18
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
19
|
+
client_options = {
|
20
|
+
:site => "http://graph.renren.com/",
|
21
|
+
:authorize_url => "/oauth/authorize",
|
22
|
+
:access_token_url => "/oauth/token"
|
23
|
+
}
|
24
|
+
|
25
|
+
super(app, :renren, client_id, client_secret, client_options, options, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def user_data
|
29
|
+
@data ||= MultiJson.decode(Net::HTTP.post_form(URI.parse('http://api.renren.com/restserver.do'), signed_params).body)[0]
|
30
|
+
end
|
31
|
+
|
32
|
+
def signed_params
|
33
|
+
params = {}
|
34
|
+
params[:api_key] = client.id
|
35
|
+
params[:method] = "users.getInfo"
|
36
|
+
params[:call_id] = Time.now.to_i
|
37
|
+
params[:format] = "json"
|
38
|
+
params[:v] = "1.0"
|
39
|
+
params[:uids] = session_key["user"]["id"]
|
40
|
+
params[:session_key] = session_key["renren_token"]["session_key"]
|
41
|
+
params[:sig] = Digest::MD5.hexdigest(params.map {|k,v| "#{k}=#{v}"}.sort.join("") + client.secret)
|
42
|
+
params
|
43
|
+
end
|
44
|
+
|
45
|
+
def session_key
|
46
|
+
@session_key ||= MultiJson.decode(@access_token.get('/renren_api/session_key'))
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_phase
|
50
|
+
options[:scope] ||= "publish_feed"
|
51
|
+
super
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_access_token
|
55
|
+
if renren_session.nil? || renrensession.empty?
|
56
|
+
super
|
57
|
+
else
|
58
|
+
@access_token = ::OAuth2::AccessToken.new(client, renren_session['access_token'])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def renren_session
|
63
|
+
session_cookie = request.cookies["rrs_#{client.id}"]
|
64
|
+
if session_cookie
|
65
|
+
@renren_session ||= Rack::Utils.parse_query(request.cookies["rrs_#{client.id}"].gsub('"', ''))
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def user_info
|
72
|
+
{
|
73
|
+
'name' => user_data["name"],
|
74
|
+
'image' => user_data["tinyurl"]
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def auth_hash
|
79
|
+
OmniAuth::Utils.deep_merge(super, {
|
80
|
+
'uid' => user_data['uid'],
|
81
|
+
'user_info' => user_info,
|
82
|
+
'extra' => {'user_hash' => user_data}
|
83
|
+
})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Salesforce < OmniAuth::Strategies::OAuth2
|
6
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
7
|
+
client_options = {
|
8
|
+
:site => 'https://login.salesforce.com',
|
9
|
+
:authorize_path => '/services/oauth2/authorize',
|
10
|
+
:access_token_path => '/services/oauth2/token'
|
11
|
+
}
|
12
|
+
|
13
|
+
options.merge!(:response_type => 'code', :grant_type => 'authorization_code')
|
14
|
+
|
15
|
+
super(app, :salesforce, consumer_key, consumer_secret, client_options, options, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def auth_hash
|
19
|
+
data = user_data
|
20
|
+
OmniAuth::Utils.deep_merge(super, {
|
21
|
+
'uid' => @access_token['id'],
|
22
|
+
'credentials' => {
|
23
|
+
'instance_url' => @access_token['instance_url']
|
24
|
+
},
|
25
|
+
'extra' => {'user_hash' => data},
|
26
|
+
'user_info' => {
|
27
|
+
'email' => data['email'],
|
28
|
+
'name' => data['display_name']
|
29
|
+
}
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
def user_data
|
34
|
+
@data ||= MultiJson.decode(@access_token.get(@access_token['id']))
|
35
|
+
rescue ::OAuth2::HTTPError => e
|
36
|
+
if e.response.status == 302
|
37
|
+
@data ||= MultiJson.decode(@access_token.get(e.response.headers['location']))
|
38
|
+
else
|
39
|
+
raise e
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to SmugMug via OAuth and retrieve basic user information.
|
8
|
+
# Usage:
|
9
|
+
# use OmniAuth::Strategies::SmugMug, 'consumerkey', 'consumersecret'
|
10
|
+
#
|
11
|
+
class SmugMug < OmniAuth::Strategies::OAuth
|
12
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
13
|
+
super(app, :smugmug, consumer_key, consumer_secret,
|
14
|
+
{:site => 'http://api.smugmug.com',
|
15
|
+
:request_token_path => "/services/oauth/getRequestToken.mg",
|
16
|
+
:access_token_path => "/services/oauth/getAccessToken.mg",
|
17
|
+
:authorize_path => "/services/oauth/authorize.mg"}, options, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def auth_hash
|
21
|
+
OmniAuth::Utils.deep_merge(super, {
|
22
|
+
'uid' => user_hash['id'],
|
23
|
+
'user_info' => user_info,
|
24
|
+
'extra' => { 'user_hash' => user_hash }
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
# user info according to schema
|
29
|
+
def user_info
|
30
|
+
{
|
31
|
+
'nickname' => user_hash['NickName'],
|
32
|
+
'name' => user_hash['NickName']
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
# info as supplied by SmugMug
|
37
|
+
def user_hash
|
38
|
+
@user_hash ||= MultiJson.decode(@access_token.get('/services/api/json/1.2.2/?method=smugmug.auth.checkAccessToken').body)['Auth']['User']
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -3,7 +3,7 @@ require 'multi_json'
|
|
3
3
|
|
4
4
|
module OmniAuth
|
5
5
|
module Strategies
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# Authenticate to SoundCloud via OAuth and retrieve basic
|
8
8
|
# user information.
|
9
9
|
#
|
@@ -11,12 +11,12 @@ module OmniAuth
|
|
11
11
|
#
|
12
12
|
# use OmniAuth::Strategies::SoundCloud, 'consumerkey', 'consumersecret'
|
13
13
|
#
|
14
|
-
|
14
|
+
|
15
15
|
class SoundCloud < OmniAuth::Strategies::OAuth
|
16
|
-
def initialize(app, consumer_key, consumer_secret)
|
17
|
-
super(app, :soundcloud, consumer_key, consumer_secret, :site => 'https://api.soundcloud.com')
|
16
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
17
|
+
super(app, :soundcloud, consumer_key, consumer_secret, {:site => 'https://api.soundcloud.com'}, options)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def auth_hash
|
21
21
|
OmniAuth::Utils.deep_merge(super, {
|
22
22
|
'uid' => user_hash['id'],
|
@@ -24,10 +24,10 @@ module OmniAuth
|
|
24
24
|
'extra' => {'user_hash' => user_hash}
|
25
25
|
})
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def user_info
|
29
29
|
user_hash = self.user_hash
|
30
|
-
|
30
|
+
|
31
31
|
{
|
32
32
|
'name' => user_hash['full_name'],
|
33
33
|
'nickname' => user_hash['username'],
|
@@ -37,10 +37,10 @@ module OmniAuth
|
|
37
37
|
'urls' => {'Website' => user_hash['website']}
|
38
38
|
}
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def user_hash
|
42
42
|
@user_hash ||= MultiJson.decode(@access_token.get('/me.json').body)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
end
|
46
|
+
end
|