oa-oauth 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/omniauth/oauth.rb
CHANGED
@@ -12,5 +12,6 @@ module OmniAuth
|
|
12
12
|
autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals'
|
13
13
|
autoload :Foursquare, 'omniauth/strategies/foursquare'
|
14
14
|
autoload :Gowalla, 'omniauth/strategies/gowalla'
|
15
|
+
autoload :Identica, 'omniauth/strategies/identica'
|
15
16
|
end
|
16
17
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Identica via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Identica, 'consumerkey', 'consumersecret'
|
13
|
+
#
|
14
|
+
class Identica < OmniAuth::Strategies::OAuth
|
15
|
+
def initialize(app, consumer_key, consumer_secret)
|
16
|
+
super(app, :identica, consumer_key, consumer_secret,
|
17
|
+
:site => 'http://identi.ca',
|
18
|
+
:request_token_path => "/api/oauth/request_token",
|
19
|
+
:access_token_path => "/api/oauth/access_token",
|
20
|
+
:authorize_path => "/api/oauth/authorize")
|
21
|
+
end
|
22
|
+
|
23
|
+
def auth_hash
|
24
|
+
OmniAuth::Utils.deep_merge(super, {
|
25
|
+
'uid' => @access_token.params[:user_id],
|
26
|
+
'user_info' => user_info,
|
27
|
+
'extra' => {'user_hash' => user_hash}
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
def user_info
|
32
|
+
user_hash = self.user_hash
|
33
|
+
|
34
|
+
{
|
35
|
+
'nickname' => user_hash['screen_name'],
|
36
|
+
'name' => user_hash['name'],
|
37
|
+
'location' => user_hash['location'],
|
38
|
+
'image' => user_hash['profile_image_url'],
|
39
|
+
'description' => user_hash['description'],
|
40
|
+
'urls' => {'Website' => user_hash['url']}
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def user_hash
|
45
|
+
@user_hash ||= MultiJson.decode(@access_token.get('/api/account/verify_credentials.json').body)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -8,25 +8,39 @@ module OmniAuth
|
|
8
8
|
class OAuth2
|
9
9
|
include OmniAuth::Strategy
|
10
10
|
|
11
|
+
attr_accessor :options, :client
|
12
|
+
|
13
|
+
class CallbackError < StandardError
|
14
|
+
attr_accessor :error, :error_reason, :error_uri
|
15
|
+
|
16
|
+
def initialize(error, error_reason=nil, error_uri=nil)
|
17
|
+
self.error = error
|
18
|
+
self.error_reason = error_reason
|
19
|
+
self.error_uri = error_uri
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
def initialize(app, name, client_id, client_secret, options = {})
|
12
24
|
super(app, name)
|
13
|
-
|
14
|
-
|
25
|
+
self.options = options
|
26
|
+
self.client = ::OAuth2::Client.new(client_id, client_secret, options)
|
15
27
|
end
|
16
28
|
|
17
29
|
protected
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def request_phase(options = {})
|
30
|
+
|
31
|
+
def request_phase
|
22
32
|
redirect client.web_server.authorize_url({:redirect_uri => callback_url}.merge(options))
|
23
33
|
end
|
24
34
|
|
25
35
|
def callback_phase
|
36
|
+
if request.params['error']
|
37
|
+
raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
|
38
|
+
end
|
39
|
+
|
26
40
|
verifier = request.params['code']
|
27
41
|
@access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
|
28
42
|
super
|
29
|
-
rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied => e
|
43
|
+
rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
|
30
44
|
fail!(:invalid_credentials, e)
|
31
45
|
end
|
32
46
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oa-oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Bleigh
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-12 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,12 +24,12 @@ dependencies:
|
|
24
24
|
requirements:
|
25
25
|
- - "="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
hash:
|
27
|
+
hash: 19
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
- 1
|
31
|
-
-
|
32
|
-
version: 0.1.
|
31
|
+
- 4
|
32
|
+
version: 0.1.4
|
33
33
|
requirement: *id001
|
34
34
|
name: oa-core
|
35
35
|
prerelease: false
|
@@ -206,6 +206,7 @@ files:
|
|
206
206
|
- lib/omniauth/strategies/foursquare.rb
|
207
207
|
- lib/omniauth/strategies/github.rb
|
208
208
|
- lib/omniauth/strategies/gowalla.rb
|
209
|
+
- lib/omniauth/strategies/identica.rb
|
209
210
|
- lib/omniauth/strategies/linked_in.rb
|
210
211
|
- lib/omniauth/strategies/oauth.rb
|
211
212
|
- lib/omniauth/strategies/oauth2.rb
|