Permalink
Browse files

fixed rack session for rails 3

  • Loading branch information...
lancejpollard committed May 11, 2010
1 parent 437ca06 commit 58510fff698e34744da32f04a9d9fb9a58b0f92c
File renamed without changes.
View
@@ -0,0 +1,9 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.0.beta3'
+gem "json"
+gem "ruby-openid"
+gem "authlogic", :git => "git://github.com/odorcicd/authlogic.git", :branch => "rails3"
+gem "oauth"
+gem "oauth2" # facebook only
+gem "authlogic-connect"
View
@@ -0,0 +1,45 @@
+README.markdown
+Rakefile
+init.rb
+MIT-LICENSE
+lib/authlogic_connect
+lib/authlogic_connect/common
+lib/authlogic_connect/common/session.rb
+lib/authlogic_connect/common/user.rb
+lib/authlogic_connect/common/variables.rb
+lib/authlogic_connect/common.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/tokens
+lib/authlogic_connect/oauth/tokens/delicious_token.rb
+lib/authlogic_connect/oauth/tokens/facebook_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
+lib/authlogic_connect/oauth/tokens/oauth_token.rb
+lib/authlogic_connect/oauth/tokens/opensocial_token.rb
+lib/authlogic_connect/oauth/tokens/photobucket_token.rb
+lib/authlogic_connect/oauth/tokens/smug_mug_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/session.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.rb
+lib/oauth_callback_filter.rb
+lib/token.rb
+rails/init.rb
View
@@ -81,8 +81,40 @@ Otherwise, add this migration
end
end
end
-
-### 4. Make sure you save your objects properly
+
+### 4. Configure your keys
+
+In `config/initializers/authlogic_connect_config.rb`, write your keys and secrets for each service you would like to support. You have to manually go to the websites and register with the service provider (list of those links coming soon, in token classes for now).
+
+ AuthlogicConnect.config = {
+ :services => {
+ :twitter => {
+ :key => "my_key",
+ :secret => "my_secret",
+ :label => "Twitter"
+ },
+ :facebook => {
+ :key => "my_key",
+ :secret => "my_secret",
+ :label => "Facebook"
+ },
+ :google => {
+ :key => "my_key",
+ :secret => "my_secret",
+ :label => "Google"
+ },
+ :yahoo => {
+ :key => "my_key",
+ :secret => "my_secret",
+ :label => "Yahoo"
+ },
+ :vimeo => {
+
+ }
+ }
+ }
+
+### 5. Make sure you save your objects properly
Because of the redirects involved in Oauth and OpenID, you MUST pass a block to the `save` method in your UsersController and UserSessionsController:
@@ -99,7 +131,7 @@ You should save your `@user` objects this way as well, because you also want the
If we don't use the block, we will get a DoubleRender error. This lets us skip that entire block and send the user along their way without any problems.
-### 5. Create Custom Tokens (if they don't already exist)
+### 6. Create Custom Tokens (if they don't already exist)
Here's an example of the FacebookToken for Oauth
View
@@ -42,7 +42,7 @@ task :publish => [:package] do
end
desc "Print a list of the files to be put into the gem"
-task :manifest => :clean do
+task :manifest do
File.open("Manifest", "w") do |f|
spec.files.each do |file|
f.puts file
@@ -3,6 +3,20 @@
require 'oauth'
require 'oauth2'
+# Throw callback rack app into the middleware stack
+# TODO: Somehow do this for Rails 3?
+# For now it is in the sample Rails 3 app
+=begin
+ActionController::Dispatcher.middleware = ActionController::MiddlewareStack.new do |m|
+ ActionController::Dispatcher.middleware.each do |klass|
+ m.use klass
+ end
+ m.use AuthlogicConnect::CallbackFilter
+end
+=end
+this = File.dirname(__FILE__)
+library = "#{this}/authlogic_connect"
+
class Hash
def recursively_symbolize_keys!
self.symbolize_keys!
@@ -66,6 +80,17 @@ def consumer(key)
end
end
-require File.dirname(__FILE__) + "/authlogic_connect/openid"
-require File.dirname(__FILE__) + "/authlogic_connect/oauth"
-require File.dirname(__FILE__) + "/authlogic_connect/common"
+require "#{library}/callback_filter"
+require "#{library}/token"
+require "#{library}/openid"
+require "#{library}/oauth"
+require "#{library}/common"
+
+custom_models = ["#{library}/token"]
+custom_models += Dir["#{library}/oauth/tokens"]
+custom_models +=Dir["#{library}/openid/tokens"]
+
+custom_models.each do |path|
+ $LOAD_PATH << path
+ ActiveSupport::Dependencies.load_paths << path
+end
@@ -1,9 +1,12 @@
-class OauthCallbackFilter
+class AuthlogicConnect::CallbackFilter
def initialize(app)
@app = app
end
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"][:oauth_callback_method].blank?
env["REQUEST_METHOD"] = env["rack.session"].delete(:oauth_callback_method).to_s.upcase
end
@@ -1,6 +1,7 @@
module AuthlogicConnect::Oauth
end
+require File.dirname(__FILE__) + "/oauth/variables"
require File.dirname(__FILE__) + "/oauth/process"
require File.dirname(__FILE__) + "/oauth/user"
require File.dirname(__FILE__) + "/oauth/session"
@@ -2,7 +2,7 @@ module AuthlogicConnect::Oauth
module Process
private
- include Variables
+ include AuthlogicConnect::Oauth::Variables
def validate_by_oauth
validate_email_field = false
@@ -3,7 +3,6 @@ module AuthlogicConnect::Oauth
# to the Authlogic::Session::Base class.
module Session
def self.included(base)
- puts "included Oauth in Session"
base.class_eval do
include InstanceMethods
end
@@ -34,8 +33,6 @@ def record=(record)
# Clears out the block if we are authenticating with oauth,
# so that we can redirect without a DoubleRender error.
def save_with_oauth(&block)
- puts "SAVE SESSION WITH OAUTH"
- puts "redirecting_to_oauth_server? #{redirecting_to_oauth_server?.to_s}"
block = nil if redirecting_to_oauth_server?
return block.nil?
end
@@ -31,4 +31,4 @@ def oauth_token
AuthlogicConnect.token(oauth_provider)
end
end
-end
+end
File renamed without changes.
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.date = %q{2010-05-10}
s.description = %q{Let your app use all of Oauth and OpenID}
s.email = %q{lancejpollard@gmail.com}
- s.files = ["README.markdown", "Rakefile", "init.rb", "MIT-LICENSE", "lib/auth_token.rb", "lib/authlogic_connect", "lib/authlogic_connect/common", "lib/authlogic_connect/common/session.rb", "lib/authlogic_connect/common/user.rb", "lib/authlogic_connect/common/variables.rb", "lib/authlogic_connect/common.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/tokens", "lib/authlogic_connect/oauth/tokens/delicious_token.rb", "lib/authlogic_connect/oauth/tokens/facebook_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", "lib/authlogic_connect/oauth/tokens/oauth_token.rb", "lib/authlogic_connect/oauth/tokens/opensocial_token.rb", "lib/authlogic_connect/oauth/tokens/photobucket_token.rb", "lib/authlogic_connect/oauth/tokens/smug_mug_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/session.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.rb", "lib/oauth_callback_filter.rb", "rails/init.rb"]
+ s.files = ["README.markdown", "Rakefile", "init.rb", "MIT-LICENSE", "lib/authlogic-connect.rb", "lib/authlogic_connect", "lib/authlogic_connect/callback_filter.rb", "lib/authlogic_connect/common", "lib/authlogic_connect/common/session.rb", "lib/authlogic_connect/common/user.rb", "lib/authlogic_connect/common/variables.rb", "lib/authlogic_connect/common.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/tokens", "lib/authlogic_connect/oauth/tokens/delicious_token.rb", "lib/authlogic_connect/oauth/tokens/facebook_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", "lib/authlogic_connect/oauth/tokens/oauth_token.rb", "lib/authlogic_connect/oauth/tokens/opensocial_token.rb", "lib/authlogic_connect/oauth/tokens/photobucket_token.rb", "lib/authlogic_connect/oauth/tokens/smug_mug_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/session.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/token.rb", "rails/init.rb"]
s.homepage = %q{http://github.com/viatropos/authlogic-connect}
s.require_paths = ["lib"]
s.rubyforge_project = %q{authlogic-connect}
@@ -21,23 +21,23 @@ Gem::Specification.new do |s|
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
- s.add_runtime_dependency(%q<activerecord>, [">= 2.3.5"])
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.1.2"])
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.1.2"])
s.add_runtime_dependency(%q<authlogic>, [">= 0"])
s.add_runtime_dependency(%q<oauth>, [">= 0"])
s.add_runtime_dependency(%q<json>, [">= 0"])
s.add_runtime_dependency(%q<oauth2>, [">= 0"])
else
- s.add_dependency(%q<activesupport>, [">= 2.3.5"])
- s.add_dependency(%q<activerecord>, [">= 2.3.5"])
+ s.add_dependency(%q<activesupport>, [">= 2.1.2"])
+ s.add_dependency(%q<activerecord>, [">= 2.1.2"])
s.add_dependency(%q<authlogic>, [">= 0"])
s.add_dependency(%q<oauth>, [">= 0"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<oauth2>, [">= 0"])
end
else
- s.add_dependency(%q<activesupport>, [">= 2.3.5"])
- s.add_dependency(%q<activerecord>, [">= 2.3.5"])
+ s.add_dependency(%q<activesupport>, [">= 2.1.2"])
+ s.add_dependency(%q<activerecord>, [">= 2.1.2"])
s.add_dependency(%q<authlogic>, [">= 0"])
s.add_dependency(%q<oauth>, [">= 0"])
s.add_dependency(%q<json>, [">= 0"])
View
@@ -1,17 +1 @@
-require "authlogic_connect"
-require "oauth_callback_filter"
-
-# Throw callback rack app into the middleware stack
-ActionController::Dispatcher.middleware = ActionController::MiddlewareStack.new do |m|
- ActionController::Dispatcher.middleware.each do |klass|
- m.use klass
- end
- m.use OauthCallbackFilter
-end
-
-custom_models = Dir["#{File.dirname(__FILE__)}/../lib/authlogic_connect/oauth/tokens"]
-custom_models +=Dir["#{File.dirname(__FILE__)}/../lib/authlogic_connect/openid/tokens"]
-custom_models.each do |path|
- $LOAD_PATH << path
- ActiveSupport::Dependencies.load_paths << path
-end
+require "authlogic-connect"

0 comments on commit 58510ff

Please sign in to comment.