Permalink
Browse files

fixed few bugs, look into password/code/extending headers. removed ac…

…cess_token
  • Loading branch information...
lancejpollard committed Jul 14, 2010
2 parents bcf06bb + 27f5cee commit f48bedd6e7cfd67e52cbb11f885cb1f77a9645ff
View
@@ -15,6 +15,7 @@ lib/authlogic_connect/oauth/session.rb
lib/authlogic_connect/oauth/tokens
lib/authlogic_connect/oauth/tokens/delicious_token.rb
lib/authlogic_connect/oauth/tokens/facebook_token.rb
+lib/authlogic_connect/oauth/tokens/foursquare_token.rb
lib/authlogic_connect/oauth/tokens/get_satisfaction_token.rb
lib/authlogic_connect/oauth/tokens/google_token.rb
lib/authlogic_connect/oauth/tokens/myspace_token.rb
@@ -39,7 +40,6 @@ lib/authlogic_connect/openid/tokens/openid_token.rb
lib/authlogic_connect/openid/user.rb
lib/authlogic_connect/openid/variables.rb
lib/authlogic_connect/openid.rb
-lib/authlogic_connect.rb
lib/oauth_callback_filter.rb
lib/token.rb
rails/init.rb
View
@@ -215,7 +215,7 @@ If they've associated their Facebook account with your site, you can access Face
## Rest...
-Thanks for the people that are already extending the project, all the input making things move much faster.
+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.
Feel free to add to the wiki if you figure things out or make new distinctions.
View
@@ -6,7 +6,7 @@ require 'rake/gempackagetask'
spec = Gem::Specification.new do |s|
s.name = "authlogic-connect"
s.author = "Lance Pollard"
- s.version = "0.0.5.1"
+ s.version = "0.0.6"
s.summary = "Authlogic Connect: Oauth and OpenID made dead simple"
s.homepage = "http://github.com/viatropos/authlogic-connect"
s.email = "lancejpollard@gmail.com"
@@ -72,4 +72,14 @@ end
task :yank do
`gem yank #{spec.name} -v #{spec.version}`
+end
+
+desc 'run unit tests'
+task :test do
+ Dir["test/**/*"].each do |file|
+ next unless File.extname(file) == ".rb"
+ next unless File.basename(file) =~ /test_/
+ next if File.basename(file) =~ /test_helper/
+ system "ruby #{file}"
+ end
end
View
@@ -21,9 +21,12 @@
custom_models += Dir["#{library}/oauth/tokens"]
custom_models += Dir["#{library}/openid/tokens"]
+# Rails 3/2 config
+load_path_method = ActiveSupport::Dependencies.respond_to?(:autoload_paths) ? :autoload_paths : :load_paths
+
custom_models.each do |path|
$LOAD_PATH << path
- ActiveSupport::Dependencies.load_paths << path
+ ActiveSupport::Dependencies.send(load_path_method) << path
end
# Rails 3beta4 backport
@@ -17,6 +17,10 @@ def settings
self.class.settings
end
+ def config
+ self.class.config
+ end
+
def get(path)
end
@@ -43,6 +47,10 @@ def config
@settings.dup
end
+ def api_version(value = nil)
+ config[:api]
+ end
+
protected
def credentials
@@ -29,4 +29,17 @@ def validate_password_with_openid?
!using_oauth? && super
end
+ # because user and session are so closely tied together, I am still
+ # uncertain as to how they are saved. So this makes sure if we are
+ # logging in, it must be saving the session, otherwise the user.
+ def correct_request_class?
+ return false unless auth_params?
+
+ if is_auth_session?
+ auth_type.to_s == "session"
+ else
+ auth_type.to_s == "user"
+ end
+ end
+
end
@@ -60,8 +60,8 @@ def save(options = {}, &block)
save_options = ActiveRecord::VERSION::MAJOR < 3 ? options[:validate] : options
# kill the block if we're starting authentication
- authenticate_via_protocol(block_given?, options) do |redirecting|
- block = nil if redirecting
+ authenticate_via_protocol(block_given?, options) do |start_authentication|
+ block = nil if start_authentication # redirecting
# forces you to validate, only if a block is given
result = super(save_options) # validate!
unless block.nil?
@@ -47,19 +47,6 @@ def from_session_or_params(attribute)
result
end
- # because user and session are so closely tied together, I am still
- # uncertain as to how they are saved. So this makes sure if we are
- # logging in, it must be saving the session, otherwise the user.
- def correct_request_class?
- return false unless auth_params?
-
- if is_auth_session?
- auth_type.to_s == "session"
- else
- auth_type.to_s == "user"
- end
- end
-
def add_session_key(key, value)
end
@@ -71,5 +71,5 @@ def cleanup_oauth_session
:_secret,
].each {|key| remove_session_key(key)}
end
-
+
end
@@ -11,7 +11,7 @@ def oauth_request?
# 2. from call
# checks that the correct session variables are there
def oauth_response?
- !oauth_response.nil? && !auth_session.nil? && auth_session[:auth_request_class] == self.class.name && auth_session[:auth_method] == "oauth"
+ !oauth_response.nil? && auth_session? && auth_session[:auth_request_class] == self.class.name && auth_session[:auth_method] == "oauth"
end
def oauth_complete?
@@ -54,7 +54,7 @@ def validate_password_with_oauth?
end
def stored_oauth_token_and_secret?
- !is_auth_session? && auth_params && auth_params.has_key?(:_key) && auth_params.has_key?(:_token) && auth_params.has_key?(:_secret)
+ !is_auth_session? && auth_params? && auth_params.has_key?(:_key) && auth_params.has_key?(:_token) && auth_params.has_key?(:_secret)
end
end
@@ -0,0 +1,15 @@
+class FoursquareToken < OauthToken
+
+ key do |access_token|
+ body = JSON.parse(access_token.get("/user.json").body)
+ user_id = body['user']['id'].to_s
+ end
+
+ settings "http://api.foursquare.com/:api_version",
+ :request_token_url => "http://foursquare.com/oauth/request_token",
+ :access_token_url => "http://foursquare.com/oauth/access_token",
+ :authorize_url => "http://foursquare.com/oauth/authorize",
+ :api_versions => {1 => "v1", 2 => "v2"},
+ :api_version => 1
+
+end
@@ -6,4 +6,4 @@ class GetSatisfactionToken < OauthToken
:authorize_url => "/api/authorize",
:access_token_path => "/api/access_token"
-end
+end
@@ -20,14 +20,26 @@ def oauth_version
self.class.oauth_version
end
- def get(path, options = {})
- client.get(path, options)
+ def get(path, headers = {})
+ client.get(path, headers)
end
-
+
def post(path, body = "", headers = {})
client.post(path, body, headers)
end
-
+
+ def head(path, headers = {})
+ client.head(path, headers)
+ end
+
+ def put(path, body = "", headers = {})
+ client.put(path, body, headers)
+ end
+
+ def delete(path, headers = {})
+ client.delete(path, headers)
+ end
+
class << self
# oauth version, 1.0 or 2.0
@@ -55,11 +67,15 @@ def oauth_key
@oauth_key
end
+ def config
+ super.merge(credentials[:options] || {})
+ end
+
def consumer
if oauth_version == 1.0
- OAuth::Consumer.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {}))
+ OAuth::Consumer.new(credentials[:key], credentials[:secret], config)
else
- OAuth2::Client.new(credentials[:key], credentials[:secret], config.merge(credentials[:options] || {}))
+ OAuth2::Client.new(credentials[:key], credentials[:secret], config)
end
end
@@ -32,7 +32,7 @@ def self.included(base)
# modules work like inheritance
def save_oauth_session
super
- auth_session[:auth_attributes] = attributes.reject!{|k, v| v.blank? || !self.respond_to?(k)} unless is_auth_session?
+ auth_session[:auth_attributes] = attributes.reject!{|k, v| v.blank? || !self.respond_to?(k)} unless is_auth_session?
end
def redirect_to_oauth
@@ -57,7 +57,6 @@ def complete_oauth_transaction
self.errors.add(:tokens, "you have already created an account using your #{token_class.service_name} account, so it")
else
self.access_tokens << token
- self.active_token = token
end
end
@@ -0,0 +1,19 @@
+class AuthlogicConnect::RackState
+ def initialize(app)
+ @app = app
+ end
+
+ # this intercepts how the browser interprets the url.
+ # so we override it and say,
+ # "if we've stored a variable in the session called :auth_callback_method,
+ # then convert that into a POST call so we re-call the original method"
+ def call(env)
+ if env["rack.session"].nil?
+ raise "Make sure you are setting the session in Rack too! Place this in config/application.rb"
+ end
+ unless env["rack.session"][:auth_callback_method].blank?
+ env["REQUEST_METHOD"] = env["rack.session"].delete(:auth_callback_method).to_s.upcase
+ end
+ @app.call(env)
+ end
+end
@@ -2,14 +2,14 @@
Gem::Specification.new do |s|
s.name = %q{authlogic-connect}
- s.version = "0.0.5.1"
+ s.version = "0.0.6"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Lance Pollard"]
- s.date = %q{2010-07-07}
+ s.date = %q{2010-07-14}
s.description = %q{Oauth and OpenID made dead simple}
s.email = %q{lancejpollard@gmail.com}
- s.files = ["README.markdown", "Rakefile", "init.rb", "MIT-LICENSE", "lib/authlogic-connect.rb", "lib/authlogic_connect", "lib/authlogic_connect/access_token.rb", "lib/authlogic_connect/authlogic_connect.rb", "lib/authlogic_connect/callback_filter.rb", "lib/authlogic_connect/common", "lib/authlogic_connect/common/session.rb", "lib/authlogic_connect/common/state.rb", "lib/authlogic_connect/common/user.rb", "lib/authlogic_connect/common/variables.rb", "lib/authlogic_connect/common.rb", "lib/authlogic_connect/engine.rb", "lib/authlogic_connect/ext.rb", "lib/authlogic_connect/oauth", "lib/authlogic_connect/oauth/helper.rb", "lib/authlogic_connect/oauth/process.rb", "lib/authlogic_connect/oauth/session.rb", "lib/authlogic_connect/oauth/state.rb", "lib/authlogic_connect/oauth/tokens", "lib/authlogic_connect/oauth/tokens/aol_token.rb", "lib/authlogic_connect/oauth/tokens/facebook_token.rb", "lib/authlogic_connect/oauth/tokens/get_satisfaction_token.rb", "lib/authlogic_connect/oauth/tokens/github_token.rb", "lib/authlogic_connect/oauth/tokens/google_token.rb", "lib/authlogic_connect/oauth/tokens/linked_in_token.rb", "lib/authlogic_connect/oauth/tokens/meetup_token.rb", "lib/authlogic_connect/oauth/tokens/myspace_token.rb", "lib/authlogic_connect/oauth/tokens/netflix_token.rb", "lib/authlogic_connect/oauth/tokens/oauth_token.rb", "lib/authlogic_connect/oauth/tokens/ohloh_token.rb", "lib/authlogic_connect/oauth/tokens/opensocial_token.rb", "lib/authlogic_connect/oauth/tokens/twitter_token.rb", "lib/authlogic_connect/oauth/tokens/vimeo_token.rb", "lib/authlogic_connect/oauth/tokens/yahoo_token.rb", "lib/authlogic_connect/oauth/user.rb", "lib/authlogic_connect/oauth/variables.rb", "lib/authlogic_connect/oauth.rb", "lib/authlogic_connect/openid", "lib/authlogic_connect/openid/process.rb", "lib/authlogic_connect/openid/session.rb", "lib/authlogic_connect/openid/state.rb", "lib/authlogic_connect/openid/tokens", "lib/authlogic_connect/openid/tokens/aol_token.rb", "lib/authlogic_connect/openid/tokens/blogger_token.rb", "lib/authlogic_connect/openid/tokens/flickr_token.rb", "lib/authlogic_connect/openid/tokens/my_openid_token.rb", "lib/authlogic_connect/openid/tokens/openid_token.rb", "lib/authlogic_connect/openid/user.rb", "lib/authlogic_connect/openid/variables.rb", "lib/authlogic_connect/openid.rb", "lib/open_id_authentication.rb", "rails/init.rb", "test/controllers", "test/controllers/test_users_controller.rb", "test/database.yml", "test/libs", "test/libs/database.rb", "test/libs/user.rb", "test/libs/user_session.rb", "test/old.rb", "test/test_authlogic_connect.rb", "test/test_helper.rb", "test/test_user.rb"]
+ s.files = ["README.markdown", "Rakefile", "init.rb", "MIT-LICENSE", "lib/authlogic-connect.rb", "lib/authlogic_connect", "lib/authlogic_connect/access_token.rb", "lib/authlogic_connect/authlogic_connect.rb", "lib/authlogic_connect/callback_filter.rb", "lib/authlogic_connect/common", "lib/authlogic_connect/common/session.rb", "lib/authlogic_connect/common/state.rb", "lib/authlogic_connect/common/user.rb", "lib/authlogic_connect/common/variables.rb", "lib/authlogic_connect/common.rb", "lib/authlogic_connect/engine.rb", "lib/authlogic_connect/ext.rb", "lib/authlogic_connect/oauth", "lib/authlogic_connect/oauth/helper.rb", "lib/authlogic_connect/oauth/process.rb", "lib/authlogic_connect/oauth/session.rb", "lib/authlogic_connect/oauth/state.rb", "lib/authlogic_connect/oauth/tokens", "lib/authlogic_connect/oauth/tokens/aol_token.rb", "lib/authlogic_connect/oauth/tokens/facebook_token.rb", "lib/authlogic_connect/oauth/tokens/foursquare_token.rb", "lib/authlogic_connect/oauth/tokens/get_satisfaction_token.rb", "lib/authlogic_connect/oauth/tokens/github_token.rb", "lib/authlogic_connect/oauth/tokens/google_token.rb", "lib/authlogic_connect/oauth/tokens/linked_in_token.rb", "lib/authlogic_connect/oauth/tokens/meetup_token.rb", "lib/authlogic_connect/oauth/tokens/myspace_token.rb", "lib/authlogic_connect/oauth/tokens/netflix_token.rb", "lib/authlogic_connect/oauth/tokens/oauth_token.rb", "lib/authlogic_connect/oauth/tokens/ohloh_token.rb", "lib/authlogic_connect/oauth/tokens/opensocial_token.rb", "lib/authlogic_connect/oauth/tokens/twitter_token.rb", "lib/authlogic_connect/oauth/tokens/vimeo_token.rb", "lib/authlogic_connect/oauth/tokens/yahoo_token.rb", "lib/authlogic_connect/oauth/user.rb", "lib/authlogic_connect/oauth/variables.rb", "lib/authlogic_connect/oauth.rb", "lib/authlogic_connect/openid", "lib/authlogic_connect/openid/process.rb", "lib/authlogic_connect/openid/session.rb", "lib/authlogic_connect/openid/state.rb", "lib/authlogic_connect/openid/tokens", "lib/authlogic_connect/openid/tokens/aol_token.rb", "lib/authlogic_connect/openid/tokens/blogger_token.rb", "lib/authlogic_connect/openid/tokens/flickr_token.rb", "lib/authlogic_connect/openid/tokens/my_openid_token.rb", "lib/authlogic_connect/openid/tokens/openid_token.rb", "lib/authlogic_connect/openid/user.rb", "lib/authlogic_connect/openid/variables.rb", "lib/authlogic_connect/openid.rb", "lib/authlogic_connect/rack_state.rb", "lib/open_id_authentication.rb", "rails/init.rb", "test/controllers", "test/controllers/test_users_controller.rb", "test/database.yml", "test/libs", "test/libs/database.rb", "test/libs/user.rb", "test/libs/user_session.rb", "test/test_helper.rb", "test/test_oauth.rb", "test/test_openid.rb", "test/test_user.rb"]
s.homepage = %q{http://github.com/viatropos/authlogic-connect}
s.require_paths = ["lib"]
s.rubyforge_project = %q{authlogic-connect}
View
@@ -17,21 +17,22 @@
t.datetime :created_at
t.datetime :updated_at
end
-
- create_table :access_tokens, :force => true do |t|
- t.integer :user_id
- t.string :type, :limit => 30
- t.string :key, :limit => 1024
- t.string :secret
- t.boolean :active
- t.datetime :created_at
- t.datetime :updated_at
+
+ create_table :access_tokens do |t|
+ t.integer :user_id
+ t.string :type, :limit => 30
+ t.string :key # how we identify the user, in case they logout and log back in
+ t.string :token, :limit => 1024 # This has to be huge because of Yahoo's excessively large tokens
+ t.string :secret
+ t.boolean :active # whether or not it's associated with the account
+ t.timestamps
end
-
+
create_table :users, :force => true do |t|
t.datetime :created_at
t.datetime :updated_at
t.string :login
+ t.string :email
t.string :crypted_password
t.string :password_salt
t.string :persistence_token, :null => false
@@ -41,8 +42,6 @@
t.datetime :current_login_at
t.string :last_login_ip
t.string :current_login_ip
- t.string :openid_identifier
- t.integer :active_token_id
end
end
View
@@ -1,53 +0,0 @@
-require 'rubygems'
-require 'tempfile'
-require 'test/unit'
-
-require 'shoulda'
-gem 'activerecord', '~>3.0.0'
-gem 'activesupport', '~>3.0.0'
-gem 'actionpack', '~>3.0.0'
-require 'active_record'
-require 'active_record/version'
-require 'active_support'
-require 'action_pack'
-gem "ruby-openid"
-gem 'rack-openid', '>=0.2.1'
-gem "authlogic", :git => "git://github.com/odorcicd/authlogic.git", :branch => "rails3"
-require 'authlogic'
-gem "oauth"
-gem "oauth2"
-
-puts "Testing against version #{ActiveRecord::VERSION::STRING}"
-
-begin
- require 'ruby-debug'
-rescue LoadError => e
- puts "debugger disabled"
-end
-
-ROOT = File.join(File.dirname(__FILE__), '..')
-
-def silence_warnings
- old_verbose, $VERBOSE = $VERBOSE, nil
- yield
-ensure
- $VERBOSE = old_verbose
-end
-
-class Test::Unit::TestCase
- def setup
- silence_warnings do
- Object.const_set(:Rails, stub('Rails', :root => ROOT, :env => 'test'))
- end
- end
-end
-
-$LOAD_PATH << File.join(ROOT, 'lib')
-$LOAD_PATH << File.join(ROOT, 'lib', 'authlogic-connect')
-
-require File.join(ROOT, 'lib', 'authlogic-connect.rb')
-
-FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
-config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
-ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
-ActiveRecord::Base.establish_connection(config['test'])
@@ -1,13 +0,0 @@
-require File.dirname(__FILE__) + '/test_helper.rb'
-
-class AuthlogicConnectTest < Test::Unit::TestCase
- context "AuthlogicConnect.config" do
- setup do
- AuthlogicConnect.config = {}
- end
-
- should "have an empty configuration hash" do
- assert_equal true, AuthlogicConnect.config.empty?
- end
- end
-end
Oops, something went wrong.

0 comments on commit f48bedd

Please sign in to comment.