gpt4 book ai didi

Facebook omniauth 原始信息验证额外的模拟配置设置

转载 作者:行者123 更新时间:2023-11-28 21:27:28 24 4
gpt4 key购买 nike

我正在尝试使用 omniauth 测试一个简单的 facebook 登录。但是,收到一条错误消息,指出“auth”未定义 variablemethodomniauth 测试文档不包含 facebook 示例

运行 cucumber 功能测试

undefined local variable or method `auth' for #<Cucumber::Rails::World:0x007fa17eeafc78> (NameError)
./features/step_definitions/microsites/quiz/microsites_quiz_entrant_sign_in_facebook_steps.rb:26:in `/^I log in with my facebook email and password quiz$/'

steps.rb文件

Then(/^I log in with my facebook email and password quiz$/) do
OmniAuth.config.add_mock(:facebook, {
:provider => "facebook",
:uid => '12345',
:name => "John Smith",
info: {
email: "test@test.com",
first_name: "Test",
last_name: "Tester",
gender: "male",
dob: auth.extra.raw_info.birthday
}
})
end

配置/环境/test.rb

OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new({
:provider => 'twitter',
:uid => '123545'
})

模型文件

  def self.from_facebook auth, campaign, password
campaign.entrants.where(fb_uid: auth.uid).first_or_create do |entrant|
entrant.fb_uid = auth.uid
entrant.email = auth.info.email
entrant.first_name = auth.info.first_name
entrant.last_name = auth.info.last_name
entrant.password = password
entrant.password_confirmation = password
entrant.campaign_id = campaign.id
# DOB is not returned from FB consistently, or not at all
entrant.dob = auth.extra.raw_info.birthday
# If DOB is returned, this create will pass, and this line should fire:
entrant.skip_confirmation!
end
end

最佳答案

您正在模拟 auth 响应,因此您无权访问 auth 对象以从中获取 dob - 相反,您想要类似的东西

OmniAuth.config.add_mock(:facebook, {
:provider => "facebook",
:uid => '12345',
:name => "John Smith",
info: {
email: "test@test.com",
first_name: "Test",
last_name: "Tester",
gender: "male"
},
'extra' => {
'raw_info' => { 'dob' => '1980-01-01 or whatever format is returned by Facebook'}
}
})

关于Facebook omniauth 原始信息验证额外的模拟配置设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35995526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com