authlogic-connect 0.0.4.06 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rake/gempackagetask'
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = "authlogic-connect"
8
8
  s.author = "Lance Pollard"
9
- s.version = "0.0.4.06"
9
+ s.version = "0.0.5"
10
10
  s.summary = "Authlogic Connect: Oauth and OpenID made dead simple"
11
11
  s.homepage = "http://github.com/viatropos/authlogic-connect"
12
12
  s.email = "lancejpollard@gmail.com"
@@ -24,4 +24,15 @@ custom_models += Dir["#{library}/openid/tokens"]
24
24
  custom_models.each do |path|
25
25
  $LOAD_PATH << path
26
26
  ActiveSupport::Dependencies.load_paths << path
27
+ end
28
+
29
+ # Rails 3beta4 backport
30
+ if defined?(ActiveSupport::HashWithIndifferentAccess)
31
+ ActiveSupport::HashWithIndifferentAccess.class_eval do
32
+ unless defined?(:symbolize_keys!)
33
+ def symbolize_keys!
34
+ symbolize_keys
35
+ end
36
+ end
37
+ end
27
38
  end
@@ -0,0 +1,12 @@
1
+ class GithubToken < OauthToken
2
+
3
+ key do |access_token|
4
+ user = JSON.parse(access_token.get("/api/v2/json/user/show"))
5
+ user["id"]
6
+ end
7
+
8
+ settings "https://github.com",
9
+ :authorize_path => "/login/oauth/authorize",
10
+ :access_token_path => "/login/oauth/access_token"
11
+
12
+ end
@@ -12,6 +12,10 @@ class OauthToken < AccessToken
12
12
  @client
13
13
  end
14
14
 
15
+ def clear
16
+ @client = nil
17
+ end
18
+
15
19
  def oauth_version
16
20
  self.class.oauth_version
17
21
  end
@@ -20,7 +24,7 @@ class OauthToken < AccessToken
20
24
  client.get(path, options)
21
25
  end
22
26
 
23
- def post(path, body='', headers ={})
27
+ def post(path, body = "", headers = {})
24
28
  client.post(path, body, headers)
25
29
  end
26
30
 
@@ -52,15 +56,11 @@ class OauthToken < AccessToken
52
56
  end
53
57
 
54
58
  def consumer
55
- unless @consumer
56
- if oauth_version == 1.0
57
- @consumer = OAuth::Consumer.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {}))
58
- else
59
- @consumer = OAuth2::Client.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {}))
60
- end
59
+ if oauth_version == 1.0
60
+ OAuth::Consumer.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {}))
61
+ else
62
+ OAuth2::Client.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {}))
61
63
  end
62
-
63
- @consumer
64
64
  end
65
65
 
66
66
  # if we're lucky we can find it by the token.
@@ -84,7 +84,8 @@ class OauthToken < AccessToken
84
84
  redirect_uri = options[:redirect_uri]
85
85
  token = options[:token]
86
86
  secret = options[:secret]
87
-
87
+ consumer = self.consumer # cached
88
+
88
89
  if oauth_version == 1.0
89
90
  access = request_token(token, secret).get_access_token(:oauth_verifier => oauth_verifier)
90
91
  result = {:token => access.token, :secret => access.secret, :key => nil}
@@ -109,8 +110,10 @@ class OauthToken < AccessToken
109
110
  # this is a cleaner method so we can access the authorize_url
110
111
  # from oauth 1 or 2
111
112
  def authorize_url(callback_url, &block)
113
+ consumer = self.consumer # cached
114
+
112
115
  if oauth_version == 1.0
113
- request = get_request_token(callback_url)
116
+ request = get_request_token(callback_url, consumer)
114
117
  yield request if block_given?
115
118
  return request.authorize_url
116
119
  else
@@ -131,8 +134,9 @@ class OauthToken < AccessToken
131
134
 
132
135
  # if you pass a hash as the second parameter to consumer.get_request_token,
133
136
  # ruby oauth will think this is a form and all sorts of bad things happen
134
- def get_request_token(callback_url)
137
+ def get_request_token(callback_url, consumer = nil)
135
138
  options = {:scope => config[:scope]} if config[:scope]
139
+ consumer ||= self.consumer
136
140
  consumer.get_request_token({:oauth_callback => callback_url}, options)
137
141
  end
138
142
 
@@ -18,7 +18,7 @@ ActiveRecord::Schema.define(:version => 1) do
18
18
  t.datetime :updated_at
19
19
  end
20
20
 
21
- create_table :tokens, :force => true do |t|
21
+ create_table :access_tokens, :force => true do |t|
22
22
  t.integer :user_id
23
23
  t.string :type, :limit => 30
24
24
  t.string :key, :limit => 1024
@@ -33,7 +33,8 @@ AuthlogicConnect.config = {
33
33
  :twitter => {
34
34
  :key => "my_key",
35
35
  :secret => "my_secret",
36
- :label => "Twitter"
36
+ :label => "Twitter",
37
+ :user_agent => "Netscape"
37
38
  },
38
39
  :facebook => {
39
40
  :key => "my_key",
@@ -190,5 +190,14 @@ module AuthlogicConnect
190
190
  end
191
191
  end
192
192
 
193
+ context "tokens" do
194
+ setup do
195
+ @token = TwitterToken.new
196
+ end
197
+
198
+ should "be version 1 since it's twitter" do
199
+ assert_equal 1.0, @token.oauth_version
200
+ end
201
+ end
193
202
  end
194
203
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlogic-connect
3
3
  version: !ruby/object:Gem::Version
4
- hash: 83
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- - 6
11
- version: 0.0.4.06
9
+ - 5
10
+ version: 0.0.5
12
11
  platform: ruby
13
12
  authors:
14
13
  - Lance Pollard
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-06-14 00:00:00 -07:00
18
+ date: 2010-07-07 00:00:00 -07:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -168,6 +167,7 @@ files:
168
167
  - lib/authlogic_connect/oauth/tokens/aol_token.rb
169
168
  - lib/authlogic_connect/oauth/tokens/facebook_token.rb
170
169
  - lib/authlogic_connect/oauth/tokens/get_satisfaction_token.rb
170
+ - lib/authlogic_connect/oauth/tokens/github_token.rb
171
171
  - lib/authlogic_connect/oauth/tokens/google_token.rb
172
172
  - lib/authlogic_connect/oauth/tokens/linked_in_token.rb
173
173
  - lib/authlogic_connect/oauth/tokens/meetup_token.rb