我在试图让客户端登录工作时遇到了很多问题,所以我将冒昧地引用其他大量问题......没有一个问题导致我的答案对我有用.
CONTEXT
*工作正常,我的意思是如果你只是复制了Ryan Bates的RailsCast(http://railscasts.com/episodes/360-facebook-authentication?view=asciicast)中的代码,它可以在没有任何其他任何东西的情况下工作
TL:DR; 我传递了以下应该有效的网址...
`http://localhost:3000/auth/facebook/callback?signed_request=ASDF.JOUYOUY`
// Obviously signed_request is a much longer string
Run Code Online (Sandbox Code Playgroud)
...但我仍然得到错误 OmniAuth::Strategies::Facebook::NoAuthorizationCodeError (must pass either a代码parameter or a signed request (viasigned_request parameter or afbsr_XXXcookie)):
故障排除日期+许多其他错误/潜在解决方案的概述
下面的代码解决方案基于Ryan Bates的RailsCast的代码:
$('#sign_in').click (e) ->
e.preventDefault()
FB.login (response) ->
window.location = '/auth/facebook/callback' if response.authResponse
Run Code Online (Sandbox Code Playgroud)
障碍#1:第三方cookie被阻止了吗?
不会导致错误,只是使它无法将应用程序连接到Facebook.
首先将您的应用程序连接到Facebook需要您使用Facebook登录,因为代码FB.login (response) -> window.location = "/auth/facebook/callback" if response.authResponse取决于其有效性authResponse及其包含的signedRequest …
javascript facebook omniauth facebook-javascript-sdk omniauth-facebook
我有一个使用Facebook登录功能的rails(4.2.0)应用程序.主要的宝石是设计(3.4.0)和omniauth-facebook(2.0.0).我已在Facebook上注册该应用程序,并一直在使用其测试应用程序进行开发.Facebook登录功能适用于开发环境.
当尝试在生产服务器上使用Facebook登录功能时,我收到错误"应用程序配置不允许给定URL:应用程序的设置不允许使用一个或多个给定的URL.它必须与网站URL或Canvas URL或域必须是App域之一的子域."
在dev env中使用的测试应用程序设置的详细信息如下 -
Settings:
Basic:
App Domains: 'localhost'
Website:
Site URL: 'http://localhost:3000'
Advanced:
OAuth Settings:
Embedded browser OAuth Login: Yes
Valid OAuth redirect URIs: "http://localhost:3000/users/auth/facebook/callback"
Run Code Online (Sandbox Code Playgroud)
生产环境中使用的注册应用程序设置的详细信息如下 -
Settings:
Basic:
App Domains: 'www.mysite.co'
Website:
Site URL: 'http://www.mysite.co'
Advanced:
OAuth Settings:
Embedded browser OAuth Login: Yes
Valid OAuth redirect URIs: "http://www.mysite.co/users/auth/facebook/callback"
Run Code Online (Sandbox Code Playgroud)
我在secretts.yml中指定了以下内容
development:
secret_key_base: some_secret_key
facebook:
app_id: test_app_id
app_secret: test_app_secret
production:
secret_key_base: some_secret_key
facebook:
app_id: registered_app_id
app_secret: registered_app_secret
Run Code Online (Sandbox Code Playgroud)
并且一直在设计初始化中使用来自secrets.yml的信用 …
我使用Devise gem为我的应用程序设置用户模型.我正在尝试使用Omniauth进行Facebook身份验证.我可以检索Name和Email数据,但我无法获取任何其他public_profile数据.在这个例子中,我试图得到Gender,但其他数据都没有.当我访问此路径时:user_omniauth_authorize_path(:facebook),调用"controllers/registrations_controller.rb"中的"facebook"操作.但是对于创建的用户user.gender,以及除姓名和电子邮件之外的所有其他数据,都会返回零.
配置/初始化/ devise.rb
config.omniauth :facebook, "<ID>", "<SECRET>", scope: 'email', display: 'popup', info_fields: 'email,name,gender'
Run Code Online (Sandbox Code Playgroud)
应用程序/模型/ devise.rb
devise :omniauthable, :omniauth_providers => [:facebook]
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.gender = auth.extra.raw_info.gender.to_s
end
end
Run Code Online (Sandbox Code Playgroud)
应用程序/控制器/ registrations_controller.rb
def facebook
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
Run Code Online (Sandbox Code Playgroud)
的Gemfile
gem 'devise'
gem 'omniauth-facebook'
Run Code Online (Sandbox Code Playgroud)
奇怪的是我甚至无法获得数据的类类型.Name …
我正在使用Omniauth-facebook和Devise-token-auth构建一个Rails-API,其中Angular和ng-token-auth用于前端.但是当用facebook登录时,我会看到错误:
undefined local variable or method `flash' for #<Devise::OmniauthCallbacksController:0x007fd027a51e10>
Run Code Online (Sandbox Code Playgroud)
似乎omniauth自动使用闪存中间件但是rails-api不包括这个,并且我没有成功禁用使用omniauth的flash.我的配置如下:
application.rb中:
require File.expand_path('../boot', __FILE__)
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module PathfinderApi
class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*', :headers => :any, …Run Code Online (Sandbox Code Playgroud) 几周来我一直在努力解决这个问题,而我无法弄明白.
我正在管理一个发布到Facebook的Ruby On Rails应用程序.开发环境位于Cloud9 IDE中,实时站点位于Heroku上.该应用程序在Developers.Facebook.com上有一个相应的帐户,其中包含完整的应用程序和与之关联的测试应用程序.
我的Heroku设置与完整的Facebook应用程序完美配合.
问题始于Facebook Test App中的Cloud9设置.每当我尝试通过API连接时,都会收到以下错误:
紧接着是这个错误:
我尝试使用以下选项为我的URL,但似乎没有任何工作:
https://{workspace}-{username}.c9.io/
https://{workspace}-{username}.c9.io:80/
https://{workspace}-{username}.c9.io:8080/
https://{workspace}-{username}.c9users.io/
https://{workspace}-{username}.c9users.io:80/
https://{workspace}-{username}.c9users.io:8080/
Run Code Online (Sandbox Code Playgroud)
这是我的FacebookAccount模型.
class FacebookAccount < ActiveRecord::Base
belongs_to :user
has_many :facebook_pages
if Rails.env.production?
FACEBOOK_APP_ID = ENV["FACEBOOK_APP_ID"]
FACEBOOK_SECRET = ENV["FACEBOOK_SECRET"]
else
FACEBOOK_APP_ID = "XXXXXXXXXXXXXXX"
FACEBOOK_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
end
def self.from_omniauth(auth)
oauth = Koala::Facebook::OAuth.new(FACEBOOK_APP_ID, FACEBOOK_SECRET)
new_access_info = oauth.exchange_access_token_info auth.credentials.token
new_access_token = new_access_info["access_token"]
new_access_expires_at = DateTime.now + new_access_info["expires"].to_i.seconds
where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |facebook_account|
facebook_account.provider = auth.provider
facebook_account.uid = auth.uid
facebook_account.name = auth.info.name
facebook_account.image = auth.info.image
facebook_account.email = …Run Code Online (Sandbox Code Playgroud) 我按照从分支到主(设计)的拉取请求,但我仍然遇到错误,我无法再将 api 部署到服务器
我也尝试了这个问题中提供的解决方案,但没有成功:
最新的 omniauth-facebook gem 破坏设计
错误:
/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/devise-4.7.3/lib/devise/omniauth.rb:12:in `<top (required)>': You are using an old OmniAuth version, please ensure you have 1.0.0.pr2 version or later installed. (RuntimeError)
Run Code Online (Sandbox Code Playgroud)
本地主机上的错误是一样的
红宝石版本:2.5.1p57
导轨 (5.1.7)
设计 (4.7.3)
omniauth (2.0.1)
omniauth-facebook (8.0.0)
omniauth-oauth2 (1.7.1)
我有兴趣学习使用rails的omniauth认证,所以我检查了不同的指南,其中还包含Railscast#360.
当我使用developers.facebook.com创建自己的应用程序时,它会为我创建一个App_id和秘密.我在线设置了应用程序并创建了一个基本的rails应用程序,它只使用了Ryan Bates指南中的步骤.
这是我的omniauth.rb文件,它会生成我收到的错误,
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['875829959136178'], ENV['<app_secret>']
end
Run Code Online (Sandbox Code Playgroud)
我试过用
provider :facebook, ENV['FACEBOOK_875829959136178'], ENV['FACEBOOK_<app_secret>']
Run Code Online (Sandbox Code Playgroud)
也.
当我调用http:// localhost:3000/auth/facebook时,我收到的错误表明"参数app_id是必需的".
我怎么能传递这个错误,
authentication ruby-on-rails omniauth facebook-authentication omniauth-facebook
我正在尝试通过Facebook登录网站设置omniauth.问题是Facebook没有发送'info'字段.
我为不同的环境设置了2个facebook应用程序.
对于一个应用程序,响应具有字段
#<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=true expires_at=14
42913734 token="CAAU6NSaozowBANJoDeZCakDuUZAiIZBGQ5cmFYRTwQwo7SK2JK7uhcRK7WIadpp
zjKfict9pMASS2k9XJZBTgnI8WJvJA42er9Xj8nuoeLjbEQo8TKB7b5hVlsOwRs5kcPpOPwyUTUc0ekF
uu2w4ubNZBMXZBw5xjGkQwZBZA46fATGOvDXJSrWOOAiQteWnkSO9JkeZC2SfmZCQqcSR0zdV52"> ex
tra=#<OmniAuth::AuthHash raw_info=#<OmniAuth::AuthHash id="xxxxxxxxxx" na
me="xxxxxxx">> info=#<OmniAuth::AuthHash::InfoHash image="http://graph.facebo
ok.com/xxxxxxxxxxx/picture" name="xxxx"> provider="facebook" uid="xxxxxxxx">
Run Code Online (Sandbox Code Playgroud)
在开发环境中,我得到了回应
#<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=true expires_at=14
42912896 token="CAAPK1ZAgrDtEBAKKvcj4jGu6iaIxYYJV7LZCJ6MZCELZCgNyowkqPeB5kHBsVw4
ZBKoZCv4DD6my4s8qhO1hJyEFzcb1IpKt03ydzWORZCR3PCf1bw6A9jRudmcJn1N37WgqckmuKUj4k1y
qb3fcRpNPxAxx0asXJlaUJTcVR5wi0sRIOc9l3yFm6XyuMA464MBz5vt9AvNcVB9DAGm5kHr"> extra
=#<OmniAuth::AuthHash raw_info=#<OmniAuth::AuthHash email="xxxxx@yahoo.co.in"
first_name="xxxx" gender="male" id="xxxxx" last_name="xxxx" link="h
ttps://www.facebook.com/app_scoped_user_id/xxxx/" locale="en_US" na
me="xxxx" timezone=10 updated_time="2015-06-06T03:35:33+0000" verified=tru
e>> info=#<OmniAuth::AuthHash::InfoHash email="xxxxxxx" first_name="
xx" image="http://graph.facebook.com/xxx/picture" last_name="xxxxx" name="xxxxx" urls=#<OmniAuth::AuthHash Facebook="https://www.facebook.c
om/app_scoped_user_id/xxxxx/"> verified=true> provider="facebook" ui
d="xxxxxxxxxxxxxxxx">
Run Code Online (Sandbox Code Playgroud)
我想知道它是否是应用程序级别设置,因为两者的代码相同.应用程序方面唯一的区别是API v2.3,其他是2.4
在开发模式下,在localhost/auth/facebook的身份验证回调阶段,我遇到以下错误
OAuth2 ::错误:{"access_token":"XXX","token_type":"bearer","expires_in":123}
这是错误的位置
这是堆栈跟踪
oauth2 (0.9.4) lib/oauth2/client.rb:140:in `get_token'
oauth2 (0.9.4) lib/oauth2/strategy/auth_code.rb:29:in `get_token'
omniauth-oauth2 (1.1.2) lib/omniauth/strategies/oauth2.rb:93:in `build_access_token'
omniauth-facebook (1.6.0) lib/omniauth/strategies/facebook.rb:145:in `block in build_access_token'
omniauth-facebook (1.6.0) lib/omniauth/strategies/facebook.rb:171:in `with_authorization_code!'
omniauth-facebook (1.6.0) lib/omniauth/strategies/facebook.rb:145:in `build_access_token'
omniauth-oauth2 (1.1.2) lib/omniauth/strategies/oauth2.rb:75:in `callback_phase'
omniauth-facebook (1.6.0) lib/omniauth/strategies/facebook.rb:71:in `callback_phase'
omniauth (1.4.2) lib/omniauth/strategy.rb:227:in `callback_call'
omniauth (1.4.2) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.4.2) lib/omniauth/strategy.rb:164:in `call'
Run Code Online (Sandbox Code Playgroud)
我使用以下宝石版本
我怀疑这是一个问题,宝石与Facebook发回的数据不兼容.
有关如何应对这一挑战的任何指示?
更新:为Deepak添加错误的图像
我正在开发一个从 facebook 获取详细信息的 Rails 应用程序。我已经从 facebook 获取了详细信息。但是当我刷新网页时,我收到了一个名为 CSRF 检测到的错误。我用过一些方法,但都失败了。
facebook Graph API 用于编辑操作。
这些是在员工控制器的内部类中添加的。
skip_before_action :verify_authenticity_token
skip_before_action :verify_authenticity_token, only: [:edit]
protect_from_forgery :only => [:edit]
skip_before_action :authenticate_user, only: [:edit]
skip_before_action :authenticate_user!
当使用 authentication_user 时(第 4 和第 5 种情况)我收到一个参数错误,
Before process_action callback :authenticate_user has not been defined .
在所有其他情况下,使用 facebook 更新页面后刷新页面时的错误是
OmniAuth::Strategies::OAuth2::CallbackError
csrf_detected | CSRF detected
PS:我使用了 'omniauth-facebook' 和 'koala' gem 进行集成。
ruby-on-rails protect-from-forgery facebook-graph-api omniauth-facebook ruby-on-rails-5
omniauth ×5
facebook ×4
devise ×3
cloud9-ide ×1
heroku ×1
javascript ×1
middleware ×1
oauth-2.0 ×1
rails-api ×1
rubygems ×1