开发者

OAuth with authlogic and twitter. Doesn't redirect properly

开发者 https://www.devze.com 2023-04-02 18:46 出处:网络
I have an issues with connecting loose end in oauth and authlogic. I\'m running rails 3.0.9 with authlogic working fine and I wanted to add on twitter login.

I have an issues with connecting loose end in oauth and authlogic. I'm running rails 3.0.9 with authlogic working fine and I wanted to add on twitter login.

The issue that I'm having is that after logging in on twitter instead being redirected to call back url defined in twitter dev settings. The app redirects to top domain while appending this to the url user_sessions?oauth_token=[t_o_k_e_n]

I don't have index action in user_sessions_controller.rb, so I get the action index couldn't be found error, but I can't decipher why I'm being redirected to this url?

My 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

My 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

I even tried adding

:oauth_callback => "http://127.0.0.1:3000/"

to the Consumer.new clause, but that didn't help.开发者_如何学JAVA

Lastly, my routes.rb looks like this:

resources :users, :user_sessions
  match 'login' => 'user_sessions#new', :as => :login
  match 'logout' => 'user_sessions#destroy', :as => :logout

Anyone has any ideas on how to troubleshoot this or had a similar problem?


https://dev.twitter.com/sites/default/files/images_documentation/oauth_diagram.png defines quite clearly what you should send and get from Twitters Oauth Provider.

Are you sure you get a oauth_callback_confirmed in step B, if so you might wanna contact Twitter why they validate your oauth_callback then modify it

0

精彩评论

暂无评论...
验证码 换一张
取 消