मैं सफलतापूर्वक चहचहाना और पेज के लिए कमर पेजप्रमाणीकरण विफल: वसीयत + OmniAuth + ट्विटर
यहाँ प्रवेश करने के लिए निर्देशित कर दिये जाने के बाद (twitter) Authentication failure! invalid_credentials: OAuth::Unauthorized, 401 Unauthorized
त्रुटि हो रही है आवेदन विन्यास
routes.rb
हैdevise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
devise.rb
config.omniauth :twitter, "KEY", "SECRET"
omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def twitter
auth = env["omniauth.auth"]
Rails.logger.info("auth is **************** #{auth.to_yaml}")
@user = user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.new
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.twitter_uid"] = auth["uid"]
redirect_to new_user_registration_url
end
end
end
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, :provider, :uid
# attr_accessible :title, :body
end
index.html.erb
<h3>Home</h3>
<%if user_signed_in? %>
<div><%="Welcome #{current_user.email}"%></div>
<div><%=link_to "Logout", destroy_user_session_path, method: :delete%></div>
<%else%>
<div><%=link_to "Sign in twitter", user_omniauth_authorize_path(:twitter)%></div>
<%end%>
कंसोल लॉग ऑन dev.twitter.com में
Started GET "https://stackoverflow.com/users/auth/twitter" for 127.0.0.1 at 2012-07-09 18:58:16 +0530
(twitter) Callback phase initiated.
(twitter) Callback phase initiated.
(twitter) Authentication failure! invalid_credentials: OAuth::Unauthorized, 401 Unauthorized
Started GET "https://stackoverflow.com/users/auth/twitter/callback?oauth_token=rLCEqgAWPtoIzce475sacKwoqU5baEdz0JnmldXE&oauth_verifier=xYPoz2LZGHQlmz4akoVGkarPtZTebCOmeWzPUqLcPA" for 127.0.0.1 at 2012-07-09 18:58:48 +0530
Processing by Users::OmniauthCallbacksController#failure as HTML
Parameters: {"oauth_token"=>"rLCEqgAWPtoIzce475sacKwoqU5baEdz0JnmldXE", "oauth_verifier"=>"xYPoz2LZGHQlmz4akoVGkarPtZTebCOmeWzPUqLcPA"}
Redirected to http://localhost:3000/users/sign_in
कॉलबैक URL इससे पहले यह http://127.0.0.1:3000
था। Devise, Omniauth and Twitter से मैंने इसे http://127.0.0.1:3000/auth/twitter/callback
में बदल दिया है लेकिन अभी भी त्रुटि
क्या कोई इस मुद्दे को सुधारने के लिए यहां सहायता करेगा?
धन्यवाद, अमित पटेल
क्या आपके पास 'devise.rb' में सही कुंजी और रहस्य है? –
हां। मैंने इसे ठीक से कॉन्फ़िगर किया है। आज मैंने इस मुद्दे की पहचान की। मैंने नीचे दिए गए उत्तर में सुझाए गए रेक को भी कॉन्फ़िगर किया है। मैंने बस omniauth.rb को हटा दिया और सर्वर को पुनरारंभ किया और यह काम करना शुरू कर दिया। –