ruby-on-rails - secret - using oauth




OAuth:: Unauthorized 401未經授權的軌道omniauth嘰嘰喳喳 (2)

omniauth.rb是什麼
ENV['75UOAIDmKrRXvXKBhNvKA'], ENV['GrIaBI0tQy2TtjOtaFL9VxT6s9qq1sV7h9yRaZW4A']

如果75UOAIDmKrRXvXKBhNvKAGrIaBI0tQy2TtjOtaFL9VxT6s9qq1sV7h9yRaZW4A是您的APP_IDAPP_SECRET那麼它應該寫為:

provider :twitter, '75UOAIDmKrRXvXKBhNvKA', 'GrIaBI0tQy2TtjOtaFL9VxT6s9qq1sV7h9yRaZW4A'

當我點擊[http://127.0.0.1:3000/auth/twitter]時,我得到了OAuth :: Unauthorized 401未經授權的錯誤導軌。 我正在使用Railscast視頻#241跟踪我的Rails應用程序的身份驗證。 我GOOGLE了很多,但無法找到答案。

 Info regarding app on twitter:
 Callback URL: [http://127.0.0.1:3000/auth/twitter/callback]
 Website: [http://127.0.0.1:3000]


### omniauth.rb 
Rails.application.config.middleware.use OmniAuth::Builder do
  # provider :developer unless Rails.env.production?
  provider :twitter, ENV['75UOAIDmKrRXvXKBhNvKA'],    ENV['GrIaBI0tQy2TtjOtaFL9VxT6s9qq1sV7h9yRaZW4A']
end

### routes.rb
Chilli::Application.routes.draw do
  resources :posts
  root :to => 'posts#index'
  #match '/auth/:twitter/callback' => 'sessions#create', :as => :auth_callback
  match 'auth/twitter/callback', to: 'sessions#create'
end

### application.html.erb
<div id="user_nav">
<%= link_to "Sign in with Twitter", "/auth/twitter"%>
</div>

### sessions_controller.rb
class SessionsController < ApplicationController
  def create
    user = User.from_omniauth(env['omniauth.auth'])
    session[:user_id] = user.id
    redirect_to root_url, notice: "Signed in."
  end
end

### user.rb
class User < ActiveRecord::Base
  attr_accessible :name, :provider, :uid
  def self.from_omniauth(auth)
    where(auth.slice("provider", "uid")).first || create_from_omniauth(auth)
  end

  def self.create_from_omniauth(auth)
    create! do |user|
      user.provider = auth["provider"]
      user.uid = auth["uid"]
      user.name = auth["info"]["nickname"]
     end
   end
 end

我有同樣的問題,固定我的問題是:

更改:

ENV['75UOAIDmKrRXvXKBhNvKA'],ENV['GrIaBI0tQy2TtjOtaFL9VxT6s9qq1sV7h9yRaZW4A']

至:

'75UOAIDmKrRXvXKBhNvKA', 'GrIaBI0tQy2TtjOtaFL9VxT6s9qq1sV7h9yRaZW4A'

在'auth'之前加一個'/':

match '/auth/:provider/callback', to: 'sessions#create', via: 'get'
match '/auth/failure', to: redirect('/'), via: 'get'