2013-02-02 35 views
0

我下面的瑞恩·貝茨投#225裝置和後omniauth修訂......一旦我點擊鏈接註冊與Twitter就帶我到Omniatuh設計的Twitter不發送用戶返回到網站

api.twitter。 com/oauth/authenticate?oauth_token = vJQeSrxYa6gXSFUspRP9wuzgHTgGRDoN5YjenRGnDcU

頁面在哪裏說授權batman-fansite使用您的帳戶?當我點擊登錄時什麼也沒有發生,我不會被髮回到我的網站,顯然不會登錄我或登錄我。

網址更改https://api.twitter.com/oauth/authenticate

,但比沒有其他情況發生了現在工作的這幾個小時,接着每一個建議可能.....

請幫助

devise.rb

 config.omniauth :twitter, ENV["I PUT MY CONSUMER KEY HERE"], ENV["I PUT MY CONSUMER PASSWORD HERE"] 

我也有一個

omniauth.rb

  Rails.application.config.middleware.use OmniAuth::Builder do 
      provider :twitter, 'I PUT MY CONSUMER KEY HERE', 'I PUT MY CONSUMER PASSWORD HERE' 
     end 

香港專業教育學院聽到了一些建議,如果你刪除omniauth.rb將自已經在你的devise.rb工作,但如果我刪除OMNIAUTH.RB我得到一個301 Unathorized錯誤和不發送給我TWITTER登錄頁......

如果我擺脫devise.rb中的代碼片段(不是整個文件只是vonfig.omniauth部分),並保持omniauth.rb我得到路由錯誤

繼承人我的

user.rb

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :token_authenticatable, :confirmable, 
    # :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
    :recoverable, :rememberable, :trackable, :validatable, :omniauthable 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me, :username 

    validates_presence_of :username 
    validates_uniqueness_of :username 

    def self.from_omniauth(auth) 
     where(auth.slice(:provider, :uid)).first_or_create do |user| 
     user.provider = auth.provider 
     user.uid = auth.uid 
     user.username = auth.info.nickname 
    end 
    end 

    def self.new_with_session(params, session) 
     if session["devise.user_attributes"] 
     new(session["devise.user_attributes"], without_protection: true) do |user| 
     user.attributes = params 
     user.valid? 
    end 
    else 
    super 
end 
end 

def password_required? 
    super && provider.blank? 
end 

def update_with_password(params, *options) 
    if encrypted_password.blank? 
    update_attributes(params, *options) 
else 
    super 
end 
end 
end 

我omniauth_callbacks_controller.rb

class OmniauthCallbacksController < Devise::OmniauthCallbacksController 
def all 
    user = User.from_omniauth(request.env["omniauth.auth"]) 
    if user.persisted? 
    flash.notice = "Signed in!" 
    sign_in_and_redirect user 
    else 
    session["devise.user_attributes"] = user.attributes 
    redirect_to new_user_registration_url 
    end 
    end 
    alias_method :twitter, :all 
    end 

的routes.rb

 devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}, 
      controllers: {omniauth_callbacks: "omniauth_callbacks"} 
在我的寶石文件

gem 'omniauth-twitter', :github => 'arunagw/omniauth-twitter' 

我已經嘗試添加omniauth寶石以及但這沒有做任何事情

,在我的觀點,我有

= link_to "Sign in with Twitter", user_omniauth_authorize_path(:twitter) 

在Twitter的開發者網站,我註冊我的網站增加了一個回調URL

和我做了應用型讀寫...我用盡只讀,但那個讓我一個401錯誤和香港專業教育學院還試圖讀取寫入和ACCESS FIRECT消息,但沒有任何工程

只送我到實際的Twitter登錄頁面的事情是,如果我檢查讀和寫

如果任何人有任何建議,請幫助

謝謝

回答

0

你必須正確設置回調。如果你在你的開發中使用本地主機那麼你的回調應該是

http://localhost:3000/auth/twitter/callback 

您還可以使用IP地址而不是本地主機即127.0.0.1

+0

我已經做了...本地主機:3000沒有工作,所以我用IP地址哪些工作......但我仍然得到相同的效果......我確信我在twitter開發站點的配置是準確的,並且我添加了正確的用戶密鑰和密碼。 – user1502223

+0

好的,也許這可能是代碼中的問題。我們需要弄清楚。 –