Tôi đã cài đặt omniauth 1.0. Ngoài ra tôi có oauth-0.4.5, oauth2-0.5.1, omniauth-facebook-1.0.0, omniauth-twitter-0.0.6.omniauth OAuthException & OAuth :: Không được phép
omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :facebook, ENV['167257285348131'], ENV['c8c722f697scb2afcf1600286c6212a9'], :scope => 'email,offline_access,read_stream', :display => 'popup'
provider :twitter, ENV['fma2L22ObJCW52QrL7uew'], ENV['4aZfhCAOdiS7ap8pHJ7I1OZslFwVWWLiAMVpYUI']
end
session_controller.rb
class SessionsController < ApplicationController
require 'omniauth-facebook'
require 'omniauth-twitter'
require 'omniauth'
def create
@user = User.find_or_create_from_auth_hash(auth_hash)
self.current_user = @user
redirect_to '/'
end
def auth_hash
request.env['omniauth.auth']
end
end
Ngoài ra tôi thêm 'omniauth' 'omniauth-facebook' 'omniauth-twitter' đá quý để gemfile
Có hai vấn đề:
- Khi tôi đi http://localhost:3000/auth/facebook tôi nhận được { "lỗi": { "message": "Thiếu thông số client_id", "type": "OAuthException" }}
Và vào liên kết graph.facebook.com/oauth/authorize?response_type=code & client_id = & redirect_uri = http% 3A% 2F% 2Flocalhost% 3A3000% 2Fauth% 2Ffacebook% 2Fcallback & phân tích cú pháp = truy vấn & phạm vi = email% 2Coffline_access% 2Cread_stream & display = popup Và không có client_id !!!
- Khi tôi đi đến http://localhost:3000/auth/twitter tôi nhận được OAuth :: trái phép
401 Unauthorized
Bất kỳ ý tưởng?
có bạn giải quyết các lỗi facebook? Nếu có, tôi có thể làm việc xung quanh không? Tôi nhận được thông báo lỗi tương tự. Nó có thể được giải quyết nếu tôi thêm bằng tay client_id để truy vấn tham số chuỗi – Vina
@Vina ENV [] ngắt nó. Cố gắng chỉ sử dụng "". Ví dụ: nhà cung cấp: facebook, '167257285348131', 'c8c722f697scb2afcf1600286c6212a9' –
Cảm ơn, nó hoạt động! Có vẻ như tôi cũng cần phải khởi động lại webrick. : D – Vina