我在 oauth 和 authlogic 中连接松散端时遇到问题。我正在使用 authlogic 运行 rails 3.0.9 工作正常,我想添加 twitter 登录。
我遇到的问题是,在登录 twitter 后,它被重定向到在 twitter 开发设置中定义的回调 url。应用程序重定向到顶级域,同时将其附加到 url user_sessions?oauth_token=[t_o_k_e_n]
我在 user_sessions_controller.rb 中没有索引操作,所以我得到了找不到操作索引的错误,但我无法破译为什么我被重定向到这个 url?
我的 user_sessions.rb
class UserSession < Authlogic::Session::Base
# def to_key
# new_record? ? nil : [ self.send(self.class.primary_key) ]
# end
#
# def persisted?
# false
# end
#
def self.oauth_consumer
OAuth::Consumer.new("asdasdsad", "asdasdasdas",
{ :site=>"http://twitter.com",
:authorize_url => "http://twitter.com/oauth/authenticate"})
end
end
我的 user_sessions_controller.rb
class UserSessionsController < ApplicationController
# GET /user_sessions/new
# GET /user_sessions/new.xml
def new
@user_session = UserSession.new
end
# POST /user_sessions
# POST /user_sessions.xml
def create
@user_session = UserSession.new(params[:user_session])
@user_session.save do |result|
if result
flash[:notice] = "Login successful!"
redirect_back_or_default root_path
else
render :action => :new
end
end
# respond_to do |format|
# if @user_session.save
# format.html { redirect_to(root_path, :notice => 'User session was successfully created.') }
# format.xml { render :xml => @user_session, :status => :created, :location => @user_session }
# else
# format.html { render :action => "new" }
# format.xml { render :xml => @user_session.errors, :status => :unprocessable_entity }
# end
# end
end
# DELETE /user_sessions/1
# DELETE /user_sessions/1.xml
def destroy
@user_session = UserSession.find
@user_session.destroy
respond_to do |format|
format.html { redirect_to(root_path, :notice => 'Goodbye!') }
format.xml { head :ok }
end
end
end
我什至尝试添加
:oauth_callback => "http://127.0.0.1:3000/"
到 Consumer.new 子句,但这并没有帮助。
最后,我的 routes.rb 看起来像这样:
resources :users, :user_sessions
match 'login' => 'user_sessions#new', :as => :login
match 'logout' => 'user_sessions#destroy', :as => :logout
有人对如何解决此问题或遇到类似问题有任何想法吗?