authlogic-connect 0.0.5.1 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,32 +1,14 @@
1
1
  # AuthlogicConnect
2
2
 
3
- AuthlogicConnect is an extension of the Authlogic library that aims to add complete and seamless Oauth and OpenID support to your application.
3
+ > Instant Oauth and OpenID support for your Rails and Sinatra Apps
4
4
 
5
- It allows you to login through any of the 30+ Oauth and OpenID providers on the Internet without having to write any of the logic yourself.
5
+ AuthlogicConnect is an extension of the Authlogic library that adds complete Oauth and OpenID support to your application. It provides a single interface to Oauth 1.0 and Oauth 2.0.
6
6
 
7
- That makes life easy and gives you a lot of power.
7
+ It currently allows you to login with Github, Facebook, Twitter, Google, LinkedIn, MySpace, Vimeo, and Yahoo Oauth providers, and all the OpenID providers. Feel free to add support for more as you need them.
8
8
 
9
- Here's a **[live example](http://authlogic-connect.heroku.com)** on Heroku ([with source](http://github.com/viatropos/authlogic-connect-example)).
9
+ Here's a **[live example](http://authlogic-connect.heroku.com)** on Heroku ([with source](http://github.com/viatropos/authlogic-connect-example)). [Here's the Docs](http://rdoc.info/projects/viatropos/authlogic-connect)
10
10
 
11
- ## Supported Providers
12
-
13
- AuthlogicConnect currently allows you to login with 7 Oauth providers and all the OpenID providers. Feel free to add support for more as you need them.
14
-
15
- ### Oauth
16
-
17
- - Twitter
18
- - Facebook
19
- - Google
20
- - LinkedIn
21
- - MySpace
22
- - Vimeo
23
- - Yahoo
24
-
25
- ### OpenID
26
-
27
- - MyOpenID
28
-
29
- ### Lists of all known providers here:
11
+ ### Lists of known providers:
30
12
 
31
13
  - [Oauth Providers](http://wiki.oauth.net/ServiceProviders)
32
14
  - [OpenID Providers](http://en.wikipedia.org/wiki/List_of_OpenID_providers)
@@ -233,7 +215,7 @@ If they've associated their Facebook account with your site, you can access Face
233
215
 
234
216
  ## Rest...
235
217
 
236
- Thanks for the people that are already extending the project, all the input making things move much faster.
218
+ Thanks for the people that are already extending the project, all the input making things move much faster. [Andrew Cove](http://github.com/andrewacove) and [Daf](http://github.com/daf) have helped me quite a bit, thanks guys.
237
219
 
238
220
  Feel free to add to the wiki if you figure things out or make new distinctions.
239
221
 
@@ -245,4 +227,8 @@ Feel free to add to the wiki if you figure things out or make new distinctions.
245
227
 
246
228
  #### Notes
247
229
 
248
- - Build mechanize tool to automatically create applications with service providers.
230
+ - Build mechanize tool to automatically create applications with service providers.
231
+
232
+ ### Todo
233
+
234
+ - Add [Andrew Cove's](http://github.com/andrewacove) idea of a "Merge Code". So if user creates Facebook account logs out, and create Twitter account, a code they can use to pass to facebook account so it knows it's associated with Twitter.
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.5.1"
9
+ s.version = "0.0.6"
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"
@@ -72,4 +72,14 @@ end
72
72
 
73
73
  task :yank do
74
74
  `gem yank #{spec.name} -v #{spec.version}`
75
+ end
76
+
77
+ desc 'run unit tests'
78
+ task :test do
79
+ Dir["test/**/*"].each do |file|
80
+ next unless File.extname(file) == ".rb"
81
+ next unless File.basename(file) =~ /test_/
82
+ next if File.basename(file) =~ /test_helper/
83
+ system "ruby #{file}"
84
+ end
75
85
  end
@@ -21,9 +21,12 @@ custom_models = ["#{library}/access_token"]
21
21
  custom_models += Dir["#{library}/oauth/tokens"]
22
22
  custom_models += Dir["#{library}/openid/tokens"]
23
23
 
24
+ # Rails 3/2 config
25
+ load_path_method = ActiveSupport::Dependencies.respond_to?(:autoload_paths) ? :autoload_paths : :load_paths
26
+
24
27
  custom_models.each do |path|
25
28
  $LOAD_PATH << path
26
- ActiveSupport::Dependencies.load_paths << path
29
+ ActiveSupport::Dependencies.send(load_path_method) << path
27
30
  end
28
31
 
29
32
  # Rails 3beta4 backport
@@ -17,6 +17,10 @@ class AccessToken < ActiveRecord::Base
17
17
  self.class.settings
18
18
  end
19
19
 
20
+ def config
21
+ self.class.config
22
+ end
23
+
20
24
  def get(path)
21
25
 
22
26
  end
@@ -43,6 +47,10 @@ class AccessToken < ActiveRecord::Base
43
47
  @settings.dup
44
48
  end
45
49
 
50
+ def api_version(value = nil)
51
+ config[:api]
52
+ end
53
+
46
54
  protected
47
55
 
48
56
  def credentials
@@ -29,4 +29,17 @@ module AuthlogicConnect::Common::State
29
29
  !using_oauth? && super
30
30
  end
31
31
 
32
+ # because user and session are so closely tied together, I am still
33
+ # uncertain as to how they are saved. So this makes sure if we are
34
+ # logging in, it must be saving the session, otherwise the user.
35
+ def correct_request_class?
36
+ return false unless auth_params?
37
+
38
+ if is_auth_session?
39
+ auth_type.to_s == "session"
40
+ else
41
+ auth_type.to_s == "user"
42
+ end
43
+ end
44
+
32
45
  end
@@ -60,8 +60,8 @@ module AuthlogicConnect::Common::User
60
60
  save_options = ActiveRecord::VERSION::MAJOR < 3 ? options[:validate] : options
61
61
 
62
62
  # kill the block if we're starting authentication
63
- authenticate_via_protocol(block_given?, options) do |redirecting|
64
- block = nil if redirecting
63
+ authenticate_via_protocol(block_given?, options) do |start_authentication|
64
+ block = nil if start_authentication # redirecting
65
65
  # forces you to validate, only if a block is given
66
66
  result = super(save_options) # validate!
67
67
  unless block.nil?
@@ -47,19 +47,6 @@ module AuthlogicConnect::Common::Variables
47
47
  result
48
48
  end
49
49
 
50
- # because user and session are so closely tied together, I am still
51
- # uncertain as to how they are saved. So this makes sure if we are
52
- # logging in, it must be saving the session, otherwise the user.
53
- def correct_request_class?
54
- return false unless auth_params?
55
-
56
- if is_auth_session?
57
- auth_type.to_s == "session"
58
- else
59
- auth_type.to_s == "user"
60
- end
61
- end
62
-
63
50
  def add_session_key(key, value)
64
51
 
65
52
  end
@@ -71,5 +71,5 @@ module AuthlogicConnect::Oauth::Process
71
71
  :_secret,
72
72
  ].each {|key| remove_session_key(key)}
73
73
  end
74
-
74
+
75
75
  end
@@ -11,7 +11,7 @@ module AuthlogicConnect::Oauth::State
11
11
  # 2. from call
12
12
  # checks that the correct session variables are there
13
13
  def oauth_response?
14
- !oauth_response.nil? && !auth_session.nil? && auth_session[:auth_request_class] == self.class.name && auth_session[:auth_method] == "oauth"
14
+ !oauth_response.nil? && auth_session? && auth_session[:auth_request_class] == self.class.name && auth_session[:auth_method] == "oauth"
15
15
  end
16
16
 
17
17
  def oauth_complete?
@@ -54,7 +54,7 @@ module AuthlogicConnect::Oauth::State
54
54
  end
55
55
 
56
56
  def stored_oauth_token_and_secret?
57
- !is_auth_session? && auth_params && auth_params.has_key?(:_key) && auth_params.has_key?(:_token) && auth_params.has_key?(:_secret)
57
+ !is_auth_session? && auth_params? && auth_params.has_key?(:_key) && auth_params.has_key?(:_token) && auth_params.has_key?(:_secret)
58
58
  end
59
59
 
60
60
  end
@@ -0,0 +1,15 @@
1
+ class FoursquareToken < OauthToken
2
+
3
+ key do |access_token|
4
+ body = JSON.parse(access_token.get("/user.json").body)
5
+ user_id = body['user']['id'].to_s
6
+ end
7
+
8
+ settings "http://api.foursquare.com/:api_version",
9
+ :request_token_url => "http://foursquare.com/oauth/request_token",
10
+ :access_token_url => "http://foursquare.com/oauth/access_token",
11
+ :authorize_url => "http://foursquare.com/oauth/authorize",
12
+ :api_versions => {1 => "v1", 2 => "v2"},
13
+ :api_version => 1
14
+
15
+ end
@@ -6,4 +6,4 @@ class GetSatisfactionToken < OauthToken
6
6
  :authorize_url => "/api/authorize",
7
7
  :access_token_path => "/api/access_token"
8
8
 
9
- end
9
+ end
@@ -20,14 +20,26 @@ class OauthToken < AccessToken
20
20
  self.class.oauth_version
21
21
  end
22
22
 
23
- def get(path, options = {})
24
- client.get(path, options)
23
+ def get(path, headers = {})
24
+ client.get(path, headers)
25
25
  end
26
-
26
+
27
27
  def post(path, body = "", headers = {})
28
28
  client.post(path, body, headers)
29
29
  end
30
-
30
+
31
+ def head(path, headers = {})
32
+ client.head(path, headers)
33
+ end
34
+
35
+ def put(path, body = "", headers = {})
36
+ client.put(path, body, headers)
37
+ end
38
+
39
+ def delete(path, headers = {})
40
+ client.delete(path, headers)
41
+ end
42
+
31
43
  class << self
32
44
 
33
45
  # oauth version, 1.0 or 2.0
@@ -55,11 +67,15 @@ class OauthToken < AccessToken
55
67
  @oauth_key
56
68
  end
57
69
 
70
+ def config
71
+ super.merge(credentials[:options] || {})
72
+ end
73
+
58
74
  def consumer
59
75
  if oauth_version == 1.0
60
- OAuth::Consumer.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {}))
76
+ OAuth::Consumer.new(credentials[:key], credentials[:secret], config)
61
77
  else
62
- OAuth2::Client.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {}))
78
+ OAuth2::Client.new(credentials[:key], credentials[:secret], config)
63
79
  end
64
80
  end
65
81
 
@@ -32,7 +32,7 @@ module AuthlogicConnect::Oauth::User
32
32
  # modules work like inheritance
33
33
  def save_oauth_session
34
34
  super
35
- auth_session[:auth_attributes] = attributes.reject!{|k, v| v.blank? || !self.respond_to?(k)} unless is_auth_session?
35
+ auth_session[:auth_attributes] = attributes.reject!{|k, v| v.blank? || !self.respond_to?(k)} unless is_auth_session?
36
36
  end
37
37
 
38
38
  def redirect_to_oauth
@@ -57,7 +57,6 @@ module AuthlogicConnect::Oauth::User
57
57
  self.errors.add(:tokens, "you have already created an account using your #{token_class.service_name} account, so it")
58
58
  else
59
59
  self.access_tokens << token
60
- self.active_token = token
61
60
  end
62
61
  end
63
62
 
@@ -6,4 +6,4 @@ class OpenidToken < AccessToken
6
6
  self.key = self.key.to_s.normalize_identifier unless self.key.blank?
7
7
  end
8
8
 
9
- end
9
+ end
@@ -0,0 +1,19 @@
1
+ class AuthlogicConnect::RackState
2
+ def initialize(app)
3
+ @app = app
4
+ end
5
+
6
+ # this intercepts how the browser interprets the url.
7
+ # so we override it and say,
8
+ # "if we've stored a variable in the session called :auth_callback_method,
9
+ # then convert that into a POST call so we re-call the original method"
10
+ def call(env)
11
+ if env["rack.session"].nil?
12
+ raise "Make sure you are setting the session in Rack too! Place this in config/application.rb"
13
+ end
14
+ unless env["rack.session"][:auth_callback_method].blank?
15
+ env["REQUEST_METHOD"] = env["rack.session"].delete(:auth_callback_method).to_s.upcase
16
+ end
17
+ @app.call(env)
18
+ end
19
+ end
@@ -17,21 +17,22 @@ ActiveRecord::Schema.define(:version => 1) do
17
17
  t.datetime :created_at
18
18
  t.datetime :updated_at
19
19
  end
20
-
21
- create_table :access_tokens, :force => true do |t|
22
- t.integer :user_id
23
- t.string :type, :limit => 30
24
- t.string :key, :limit => 1024
25
- t.string :secret
26
- t.boolean :active
27
- t.datetime :created_at
28
- t.datetime :updated_at
20
+
21
+ create_table :access_tokens do |t|
22
+ t.integer :user_id
23
+ t.string :type, :limit => 30
24
+ t.string :key # how we identify the user, in case they logout and log back in
25
+ t.string :token, :limit => 1024 # This has to be huge because of Yahoo's excessively large tokens
26
+ t.string :secret
27
+ t.boolean :active # whether or not it's associated with the account
28
+ t.timestamps
29
29
  end
30
-
30
+
31
31
  create_table :users, :force => true do |t|
32
32
  t.datetime :created_at
33
33
  t.datetime :updated_at
34
34
  t.string :login
35
+ t.string :email
35
36
  t.string :crypted_password
36
37
  t.string :password_salt
37
38
  t.string :persistence_token, :null => false
@@ -41,8 +42,6 @@ ActiveRecord::Schema.define(:version => 1) do
41
42
  t.datetime :current_login_at
42
43
  t.string :last_login_ip
43
44
  t.string :current_login_ip
44
- t.string :openid_identifier
45
- t.integer :active_token_id
46
45
  end
47
46
 
48
47
  end
@@ -8,6 +8,7 @@ require "active_record"
8
8
  require "active_record/fixtures"
9
9
  require 'action_controller'
10
10
  require 'shoulda'
11
+ require 'mocha'
11
12
 
12
13
  require File.dirname(__FILE__) + '/libs/database'
13
14
  require File.dirname(__FILE__) + '/../lib/authlogic-connect' unless defined?(AuthlogicConnect)
@@ -26,30 +27,33 @@ unless defined?(::ActiveModel)
26
27
  end
27
28
  end
28
29
 
29
-
30
30
  AuthlogicConnect.config = {
31
31
  :default => "twitter",
32
32
  :connect => {
33
33
  :twitter => {
34
34
  :key => "my_key",
35
35
  :secret => "my_secret",
36
- :label => "Twitter",
37
- :user_agent => "Netscape"
36
+ :headers => {
37
+ "User-Agent" => "Safari",
38
+ "MyApp-Version" => "1.2"
39
+ },
40
+ :api_version => 1
38
41
  },
39
42
  :facebook => {
40
43
  :key => "my_key",
41
- :secret => "my_secret",
42
- :label => "Facebook"
44
+ :secret => "my_secret"
45
+ },
46
+ :foursquare => {
47
+ :key => "my_key",
48
+ :secret => "my_secret"
43
49
  },
44
50
  :google => {
45
51
  :key => "my_key",
46
- :secret => "my_secret",
47
- :label => "Google"
52
+ :secret => "my_secret"
48
53
  },
49
54
  :yahoo => {
50
55
  :key => "my_key",
51
- :secret => "my_secret",
52
- :label => "Yahoo"
56
+ :secret => "my_secret"
53
57
  },
54
58
  :vimeo => {
55
59
 
@@ -99,6 +103,27 @@ class ActiveSupport::TestCase
99
103
  fixtures :all
100
104
  setup :activate_authlogic
101
105
 
106
+ def create_token
107
+ token = OAuth::RequestToken.new("twitter", "key", "secret")
108
+ token.params = {
109
+ :oauth_callback_confirmed => "true",
110
+ :oauth_token_secret => "secret",
111
+ :oauth_token => "key"
112
+ }
113
+ token.consumer = OAuth::Consumer.new("key", "secret",
114
+ :site => "http://twitter.com",
115
+ :proxy => nil,
116
+ :oauth_version => "1.0",
117
+ :request_token_path => "/oauth/request_token",
118
+ :authorize_path => "/oauth/authorize",
119
+ :scheme => :header,
120
+ :signature_method => "HMAC-SHA1",
121
+ :authorize_url => "http://twitter.com/oauth/authenticate",
122
+ :access_token_path => "/oauth/access_token"
123
+ )
124
+ token
125
+ end
126
+
102
127
  private
103
128
  def password_for(user)
104
129
  case user
@@ -0,0 +1,178 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ module AuthlogicConnect
4
+ class OauthTest < ActiveSupport::TestCase
5
+ context "Oauth (with TwitterToken)" do
6
+ setup do
7
+ @user = User.new(:login => "viatropos")
8
+ controller.params.merge!(:authentication_type => "user")
9
+ Authlogic::Session::Base.controller = controller
10
+
11
+ # this is the only thing the controller passes through for oauth
12
+ @user.auth_controller.params.merge!(:oauth_provider => "twitter")
13
+
14
+ # mock token
15
+ @token = create_token
16
+
17
+ @session_vars = [
18
+ :authentication_type,
19
+ :auth_request_class,
20
+ :oauth_provider,
21
+ :auth_callback_method
22
+ ]
23
+ end
24
+
25
+ context "REQUEST (with TwitterToken)" do
26
+
27
+ should "have an 'oauth_provider'" do
28
+ assert_equal "twitter", @user.auth_params[:oauth_provider]
29
+ assert_equal true, @user.oauth_provider?
30
+ # session hasn't started yet
31
+ assert_equal false, @user.auth_session?
32
+ end
33
+
34
+ should "be an 'oauth_request'" do
35
+ assert_equal true, @user.oauth_request?
36
+ # oauth_request? == (auth_params? && oauth_provider?)
37
+ assert_equal true, @user.auth_params?
38
+ assert_equal true, @user.oauth_provider?
39
+ end
40
+
41
+ should "not be an 'oauth_response'" do
42
+ assert_equal false, @user.oauth_response?
43
+ # oauth_response? == (!oauth_response.nil? && auth_session? && auth_session[:auth_request_class] == self.class.name && auth_session[:auth_method] == "oauth")
44
+ assert_equal false, !@user.oauth_response.nil?
45
+ assert_equal false, @user.auth_session?
46
+ assert_equal false, @user.stored_oauth_token_and_secret?
47
+ end
48
+
49
+ should "be using oauth" do
50
+ # all of the above too!
51
+ assert @user.using_oauth?
52
+ end
53
+
54
+ should "start authentication" do
55
+ assert_equal true, @user.start_authentication?
56
+ # start_authentication? == (start_oauth? || start_openid?)
57
+ assert_equal true, @user.start_oauth?
58
+ # start_oauth == (authenticating_with_oauth? && !oauth_complete?)
59
+ assert_equal true, @user.authenticating_with_oauth?
60
+ # authenticating_with_oauth? == (correct_request_class? && using_oauth?)
61
+ assert_equal true, @user.correct_request_class?
62
+ assert_equal true, @user.using_oauth?
63
+ assert_equal true, !@user.oauth_complete?
64
+ end
65
+
66
+ should "not be using openid" do
67
+ assert_equal false, @user.start_openid?
68
+ assert_equal false, @user.using_openid?
69
+ assert_equal false, @user.openid_request?
70
+ # openid_request? == (!openid_identifier.blank? && auth_session[:auth_attributes].nil?)
71
+ assert_equal false, @user.openid_response?
72
+ # openid_response? == (auth_controller? && !auth_session[:auth_attributes].nil? && auth_session[:auth_method] == "openid")
73
+ end
74
+
75
+ should "have the correct class (authentication_type == user)" do
76
+ assert_equal "user", @user.auth_params[:authentication_type]
77
+ assert @user.correct_request_class?
78
+ end
79
+
80
+ should "realize we are authenticating_with_oauth?" do
81
+ assert_equal true, @user.authenticating_with_oauth?
82
+ end
83
+ end
84
+
85
+ context "SAVE" do
86
+ setup do
87
+ @user.save
88
+ request_token = {:token => "a_token", :secret => "a_secret"}
89
+ # mock out like we've saved the data just before the first redirect
90
+ @user.save_oauth_session
91
+ @user.auth_session[:oauth_request_token] = request_token[:token]
92
+ @user.auth_session[:oauth_request_token_secret] = request_token[:secret]
93
+ end
94
+
95
+ should "save without a block" do
96
+ assert_equal true, @user.authenticating_with_oauth?
97
+ assert_equal true, @user.valid?
98
+ end
99
+
100
+ should "still be an oauth request" do
101
+ assert_equal true, @user.oauth_request?
102
+ end
103
+
104
+ context "RESPONSE (with TwitterToken)" do
105
+ setup do
106
+ @key_and_secret = {:key => "a_key", :secret => "a_secret", :token => "a_token"}
107
+ @user.auth_controller.params.merge!(:oauth_token => @key_and_secret[:token])
108
+ TwitterToken.stubs(:get_token_and_secret).returns(@key_and_secret)
109
+ end
110
+
111
+ should "have TwitterToken" do
112
+ assert_equal TwitterToken, @user.token_class
113
+ assert 1.0, @user.token_class.oauth_version
114
+ end
115
+
116
+ should "have oauth token" do
117
+ assert @user.auth_params
118
+ assert_equal true, @user.auth_params?
119
+ assert_equal "a_token", @user.oauth_token
120
+ end
121
+
122
+ should "not be an 'oauth_request'" do
123
+ assert_equal true, @user.auth_params?
124
+ assert_equal true, @user.oauth_provider?
125
+ assert_equal false, @user.oauth_response.blank?
126
+ #assert_equal false, @user.oauth_request?
127
+ # need a better way of checking this!
128
+ end
129
+
130
+ should "be an 'oauth_response'" do
131
+ assert_equal true, !@user.oauth_response.nil?
132
+ assert_equal true, @user.auth_session?
133
+ assert_equal true, (@user.auth_session[:auth_request_class] == @user.class.name)
134
+ assert_equal true, (@user.auth_session[:auth_method] == "oauth")
135
+ assert_equal true, @user.oauth_response?
136
+ end
137
+
138
+ should "be using oauth" do
139
+ assert_equal true, @user.using_oauth?
140
+ end
141
+
142
+ should "not be using openid" do
143
+ assert_equal false, @user.using_openid?
144
+ end
145
+
146
+ should "not be an 'openid_request'" do
147
+ assert_equal false, @user.using_openid?
148
+ end
149
+
150
+ should "not be an 'openid_response" do
151
+ assert_equal false, @user.using_openid?
152
+ end
153
+
154
+ teardown do
155
+ #TwitterToken.unstub(:get_token_and_secret)
156
+ end
157
+ end
158
+ end
159
+
160
+ end
161
+
162
+ context "tokens" do
163
+ setup do
164
+ @token = TwitterToken.new
165
+ end
166
+
167
+ should "be version 1 since it's twitter" do
168
+ assert_equal 1.0, @token.oauth_version
169
+ end
170
+
171
+ should "return a new consumer with each call" do
172
+ first_consumer = @token.consumer
173
+ second_consumer = @token.consumer
174
+ assert_not_equal first_consumer, second_consumer
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ module AuthlogicConnect
4
+ class OpenIdTest < Test::Unit::TestCase
5
+ context "OpenId" do
6
+ setup do
7
+ @user = User.new(:login => "viatropos")
8
+ controller.params.merge!(:authentication_type => "user")
9
+ Authlogic::Session::Base.controller = controller
10
+ @user.auth_controller.params.merge!(:openid_identifier => "viatropos.myopenid.com")
11
+ @session_vars = [
12
+ :authentication_type,
13
+ :auth_request_class,
14
+ :openid_identifier,
15
+ :auth_callback_method
16
+ ]
17
+ end
18
+
19
+ should "have an 'openid_identifier'" do
20
+ assert_equal true, @user.openid_identifier?
21
+ end
22
+
23
+ should "be an 'openid_request'" do
24
+ assert @user.openid_request?
25
+ end
26
+
27
+ should "not be an 'openid_response'" do
28
+ assert_equal false, @user.openid_response?
29
+ end
30
+
31
+ should "be using openid" do
32
+ assert @user.using_openid?
33
+ end
34
+
35
+ should "not be using oauth" do
36
+ assert_equal false, @user.using_oauth?
37
+ end
38
+
39
+ should "have the correct class (authentication_type == user)" do
40
+ assert @user.correct_request_class?
41
+ end
42
+
43
+ should "realize we are authenticating_with_openid?" do
44
+ assert @user.authenticating_with_openid?
45
+ end
46
+
47
+ context "and 'save_with_openid', manually checking each step" do
48
+
49
+ setup do
50
+ # mock save
51
+ # this, and the whole redirect process happens
52
+ # but we'll just assume we saved the session data and got the redirect back
53
+ @user.save_openid_session
54
+ @user.save(:skip_redirect => true, :keep_session => true) do
55
+ "I'm the block you want"
56
+ end
57
+ # copy to test controller
58
+ @user.auth_session.each do |key, value|
59
+ @user.auth_controller.session[key] = value
60
+ end
61
+ end
62
+
63
+ teardown do
64
+ @user.destroy
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -6,7 +6,7 @@ module AuthlogicConnect
6
6
  setup do
7
7
  @user = User.new(:login => "viatropos")
8
8
  end
9
-
9
+
10
10
  should "make sure we are loading the models" do
11
11
  assert_equal "viatropos", @user.login
12
12
  end
@@ -44,159 +44,41 @@ module AuthlogicConnect
44
44
  assert @user.auth_session.empty?
45
45
  assert_equal false, @user.auth_session?
46
46
  end
47
+
48
+ end
49
+
50
+ context "save the user without any parameters" do
47
51
 
48
- context "save the user without any parameters" do
49
-
50
- setup do
51
- @save_success = @user.save
52
- end
53
-
54
- should "be a valid save" do
55
- assert @save_success
56
- end
57
-
58
- should "not be using oauth" do
59
- assert_equal false, @user.using_oauth?
60
- end
61
-
62
- should "not be using openid" do
63
- assert_equal false, @user.using_openid?
64
- end
65
-
52
+ setup do
53
+ @save_success = @user.save
66
54
  end
67
55
 
68
- context "with oauth parameters" do
69
-
70
- setup do
71
- @user.auth_controller.params.merge!(:oauth_provider => "twitter")
72
- # mock token
73
- @token = OAuth::RequestToken.new("twitter", "key", "secret")
74
- @token.params = {
75
- :oauth_callback_confirmed => "true",
76
- :oauth_token_secret=>"secret",
77
- :oauth_token=>"key"
78
- }
79
- @token.consumer = OAuth::Consumer.new("key", "secret",
80
- :site=>"http://twitter.com",
81
- :proxy=>nil,
82
- :oauth_version=>"1.0",
83
- :request_token_path=>"/oauth/request_token",
84
- :authorize_path=>"/oauth/authorize",
85
- :scheme=>:header,
86
- :signature_method=>"HMAC-SHA1",
87
- :authorize_url=>"http://twitter.com/oauth/authenticate",
88
- :access_token_path=>"/oauth/access_token"
89
- )
90
- @session_vars = [
91
- :authentication_type,
92
- :auth_request_class,
93
- :oauth_provider,
94
- :auth_callback_method
95
- ]
96
- end
97
-
98
- should "have an 'oauth_provider'" do
99
- assert @user.oauth_provider?
100
- end
101
-
102
- should "be an 'oauth_request'" do
103
- assert @user.oauth_request?
104
- end
105
-
106
- should "not be an 'oauth_response'" do
107
- assert_equal false, @user.oauth_response?
108
- end
109
-
110
- should "be using oauth" do
111
- assert @user.using_oauth?
112
- end
113
-
114
- should "not be using openid" do
115
- assert_equal false, @user.using_openid?
116
- end
117
-
118
- should "have the correct class (authentication_type == user)" do
119
- assert @user.correct_request_class?
120
- end
121
-
122
- should "realize we are authenticating_with_oauth?" do
123
- assert @user.authenticating_with_oauth?
124
- end
125
-
56
+ should "be a valid save" do
57
+ assert @save_success
126
58
  end
127
59
 
128
- context "with openid parameters" do
129
- setup do
130
- @user.auth_controller.params.merge!(:openid_identifier => "viatropos.myopenid.com")
131
- @session_vars = [
132
- :authentication_type,
133
- :auth_request_class,
134
- :openid_identifier,
135
- :auth_callback_method
136
- ]
137
- end
138
-
139
- should "have an 'openid_identifier'" do
140
- assert_equal true, @user.openid_identifier?
141
- end
142
-
143
- should "be an 'openid_request'" do
144
- assert @user.openid_request?
145
- end
146
-
147
- should "not be an 'openid_response'" do
148
- assert_equal false, @user.openid_response?
149
- end
150
-
151
- should "be using openid" do
152
- assert @user.using_openid?
153
- end
154
-
155
- should "not be using oauth" do
156
- assert_equal false, @user.using_oauth?
157
- end
158
-
159
- should "have the correct class (authentication_type == user)" do
160
- assert @user.correct_request_class?
161
- end
162
-
163
- should "realize we are authenticating_with_openid?" do
164
- assert @user.authenticating_with_openid?
165
- end
166
-
167
- context "and 'save_with_openid', manually checking each step" do
168
-
169
- setup do
170
- # mock save
171
- # this, and the whole redirect process happens
172
- # but we'll just assume we saved the session data and got the redirect back
173
- @user.save_openid_session
174
- @user.save(:skip_redirect => true, :keep_session => true) do
175
- "I'm the block you want"
176
- end
177
- # copy to test controller
178
- @user.auth_session.each do |key, value|
179
- @user.auth_controller.session[key] = value
180
- end
181
- end
182
-
183
- teardown do
184
- @user.destroy
185
- end
186
-
187
- end
60
+ should "not be using oauth" do
61
+ assert_equal false, @user.using_oauth?
62
+ # using_oauth? == (oauth_request? || oauth_response? || stored_oauth_token_and_secret?)
63
+ assert_equal false, @user.oauth_request?
64
+ # oauth_request? == (auth_params? && oauth_provider?)
65
+ assert_equal false, @user.auth_params?
66
+ assert_equal false, @user.oauth_provider?
67
+ assert_equal false, @user.oauth_response?
68
+ # oauth_response? == (!oauth_response.nil? && auth_session? && auth_session[:auth_request_class] == self.class.name && auth_session[:auth_method] == "oauth")
69
+ assert_equal false, !@user.oauth_response.nil?
70
+ assert_equal false, @user.auth_session?
71
+ assert_equal false, @user.stored_oauth_token_and_secret?
188
72
  end
189
-
190
- end
191
- end
192
-
193
- context "tokens" do
194
- setup do
195
- @token = TwitterToken.new
73
+
74
+ should "not be using openid" do
75
+ assert_equal false, @user.using_openid?
76
+ end
77
+
196
78
  end
197
79
 
198
- should "be version 1 since it's twitter" do
199
- assert_equal 1.0, @token.oauth_version
80
+ context "user with required password field" do
81
+
200
82
  end
201
83
  end
202
84
  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: 89
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- - 1
11
- version: 0.0.5.1
9
+ - 6
10
+ version: 0.0.6
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-07-07 00:00:00 -07:00
18
+ date: 2010-07-14 00:00:00 -07:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -167,6 +166,7 @@ files:
167
166
  - lib/authlogic_connect/oauth/state.rb
168
167
  - lib/authlogic_connect/oauth/tokens/aol_token.rb
169
168
  - lib/authlogic_connect/oauth/tokens/facebook_token.rb
169
+ - lib/authlogic_connect/oauth/tokens/foursquare_token.rb
170
170
  - lib/authlogic_connect/oauth/tokens/get_satisfaction_token.rb
171
171
  - lib/authlogic_connect/oauth/tokens/github_token.rb
172
172
  - lib/authlogic_connect/oauth/tokens/google_token.rb
@@ -194,6 +194,7 @@ files:
194
194
  - lib/authlogic_connect/openid/user.rb
195
195
  - lib/authlogic_connect/openid/variables.rb
196
196
  - lib/authlogic_connect/openid.rb
197
+ - lib/authlogic_connect/rack_state.rb
197
198
  - lib/open_id_authentication.rb
198
199
  - rails/init.rb
199
200
  - test/controllers/test_users_controller.rb
@@ -201,9 +202,9 @@ files:
201
202
  - test/libs/database.rb
202
203
  - test/libs/user.rb
203
204
  - test/libs/user_session.rb
204
- - test/old.rb
205
- - test/test_authlogic_connect.rb
206
205
  - test/test_helper.rb
206
+ - test/test_oauth.rb
207
+ - test/test_openid.rb
207
208
  - test/test_user.rb
208
209
  has_rdoc: true
209
210
  homepage: http://github.com/viatropos/authlogic-connect
@@ -1,53 +0,0 @@
1
- require 'rubygems'
2
- require 'tempfile'
3
- require 'test/unit'
4
-
5
- require 'shoulda'
6
- gem 'activerecord', '~>3.0.0'
7
- gem 'activesupport', '~>3.0.0'
8
- gem 'actionpack', '~>3.0.0'
9
- require 'active_record'
10
- require 'active_record/version'
11
- require 'active_support'
12
- require 'action_pack'
13
- gem "ruby-openid"
14
- gem 'rack-openid', '>=0.2.1'
15
- gem "authlogic", :git => "git://github.com/odorcicd/authlogic.git", :branch => "rails3"
16
- require 'authlogic'
17
- gem "oauth"
18
- gem "oauth2"
19
-
20
- puts "Testing against version #{ActiveRecord::VERSION::STRING}"
21
-
22
- begin
23
- require 'ruby-debug'
24
- rescue LoadError => e
25
- puts "debugger disabled"
26
- end
27
-
28
- ROOT = File.join(File.dirname(__FILE__), '..')
29
-
30
- def silence_warnings
31
- old_verbose, $VERBOSE = $VERBOSE, nil
32
- yield
33
- ensure
34
- $VERBOSE = old_verbose
35
- end
36
-
37
- class Test::Unit::TestCase
38
- def setup
39
- silence_warnings do
40
- Object.const_set(:Rails, stub('Rails', :root => ROOT, :env => 'test'))
41
- end
42
- end
43
- end
44
-
45
- $LOAD_PATH << File.join(ROOT, 'lib')
46
- $LOAD_PATH << File.join(ROOT, 'lib', 'authlogic-connect')
47
-
48
- require File.join(ROOT, 'lib', 'authlogic-connect.rb')
49
-
50
- FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
51
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
52
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
53
- ActiveRecord::Base.establish_connection(config['test'])
@@ -1,13 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class AuthlogicConnectTest < Test::Unit::TestCase
4
- context "AuthlogicConnect.config" do
5
- setup do
6
- AuthlogicConnect.config = {}
7
- end
8
-
9
- should "have an empty configuration hash" do
10
- assert_equal true, AuthlogicConnect.config.empty?
11
- end
12
- end
13
- end