我正在使用OmniAuth和google-oauth-2策略从谷歌获取日历数据.
如果我没有在scope字段中放置任何内容它工作正常,我得到没有auth/failure消息的默认信息,我可以正常使用该应用程序.
但是,当我添加一个范围时,如下例所示,我得到一个"auth/failure?message = invalid_credentials".
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV['TEST_KEY'], ENV['TEST_SECRET'], { :scope => 'https://www.google.com/calendar/feeds/' }
end
Run Code Online (Sandbox Code Playgroud)
有什么我缺少的东西或我应该改变的东西?
我正在通过Railscast实施Devise和OmniAuth(以及Devise 文档) - 目前,我有一个网站,访问者可以使用他们的Facebook帐户或填写表格进行注册.
但是,当通过OmniAuth注册的用户尝试编辑他们的个人资料时,我遇到了麻烦.当用户提交对其个人资料的更改时,Devise会查找用户的当前密码,但是使用facebook登录的用户不知道他们的密码(他们是在用户模型中自动设置的):
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
unless user
user = User.create(first_name:auth.extra.raw_info.first_name,
last_name:auth.extra.raw_info.last_name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20]
)
end
user
end
Run Code Online (Sandbox Code Playgroud)
当用户编辑他的信息时,如果他通过OmniAuth设置了他的帐户,则该应用程序不应要求密码确认.教程建议方便的password_required?方法将帮助我实现这一结果.具体来说,将此方法添加到用户模型意味着它应该仅在用户未通过OmniAuth注册时返回true(在这种情况下提供者属性将为nil):
def password_required?
super && provider.blank?
end
Run Code Online (Sandbox Code Playgroud)
因此,一段代码如:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<%= render :partial => "essential_user_info_inputs", :locals => { :f => f } %>
<%= render :partial => "inessential_user_info_inputs", :locals => …Run Code Online (Sandbox Code Playgroud) 我已经按照本教程(http://railscasts.com/episodes/236-omniauth-part-2)使用OmniAuth和Devise创建facebook登录,我收到此错误:在我的路由中自动加载常量用户时检测到循环依赖性. RB
devise_for :users , :controllers => {:registrations => 'registrations'}
Run Code Online (Sandbox Code Playgroud)
registrations_controller.rb
Class RegistrationsController < Devise::RegistrationsController
def create
super
session[:omniauth] = nil unless @user.new_record?
end
private
def build_resource(*args)
super
if session["devise.omniauth"]
@user.apply_omniauth(session["devise.omniauth"])
session["devise.omniauth"] = nil
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是来自AuthenticationsController的我的创建方法
def create
omniauth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, authentication.user)
elsif current_user
current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
else
user = User.new
user.apply_omniauth(omniauth)
if user.save
flash[:notice] …Run Code Online (Sandbox Code Playgroud) 我用我的设计模型实现了omniauth,所以我可以使用其他服务进行身份验证.我的模型不再需要密码,因为用户可以使用twitter,facebook进行身份验证...
一切正常,但是,当用户尝试编辑其注册时,设计会跳过该过程,因为用户没有通知'current_password'(现在在某些情况下不存在).
我创建了一个注册控制器来覆盖一个设备:
class RegistrationsController < Devise::RegistrationsController
def update
super
end
end
Run Code Online (Sandbox Code Playgroud)
但是我没有找到任何关于如何跳过密码验证的文档,我怎样才能在更新操作中执行此操作?
我希望其他人有一个很好的解决方案来解决这个问题.我们让用户使用Facebook注册(通过喜欢应用程序),同时他们以我们网站上的用户身份进入我们的数据库.
注册成功后,似乎Devise/OmniAuth正在创建一个随机密码(?).如何让用户编辑他们的个人资料,默认情况下(和应该)在Devise中要求他们输入他们当前的密码?
我正在使用Web客户端和iPhone客户端构建应用程序.
在Web客户端上,我通过Facebook使用Omniauth对用户进行身份验证,然后用户可以将应用上的操作发布到Facebook.这很好用.
我在从iPhone应用程序实现Auth流程时遇到一些问题.
我在rails应用程序中将Doorkeeper设置为OAuth提供程序.虽然我不确定如何实现身份验证流程.
我想出了这个:用户可以在iPhone中登录Facebook并获得令牌.然后我们的想法是将令牌以及Facebook uid发送到rails应用程序,存储它,并使用Omniauth对用户进行身份验证.一旦用户通过身份验证,就会生成一个带有Doorkeeper的令牌并将其发送回iPhone应用程序.
如果这是用户第一次针对rails应用进行身份验证,则会创建一个新用户.
然后,用户可以针对JSON-api执行操作,并且rails app将负责Facebook集成,因为Facebook令牌存储在用户记录中.
该应用程序还将跨越多个域,因此我需要注册多个Doorkeeper应用程序以提供不同的回调uri.
这似乎是一个可行的解决方案吗?它安全吗?有替代流量/方法吗?
谢谢.
如何更改触发omniauth的路由从/ auth /:provider到/ myapp/auth /:provider?
我也不想重定向,因为我的服务器会将不在/ myapp /中的任何内容发送到错误的地方.
在尝试"使用Google登录"后,我在日志中看到此错误:
Processing by Users::OmniauthCallbacksController#failure as HTML
Run Code Online (Sandbox Code Playgroud)
我可以通过URL(在日志中)看到谷歌发送的所有数据,包括用户电子邮件和姓名.那怎么可能出错?我的回调甚至没有被执行.我只能被重定向到我网站的sign_in页面.
而且我很确定一切都配置正确,因为这在几周前工作正常.我认为我没有改变任何东西.Facebook登录仍然正常.
有关如何调试此故障的任何想法?除了那些充满参数和值的长URL之外,日志中没有其他内容.只有INFO消息.上面发布的是唯一一个关于失败的人.
UPDATE
我向控制器添加了"故障"方法
def failure
render :text => params.inspect
end
Run Code Online (Sandbox Code Playgroud)
哪个停止了重定向,并打印出来:
{}
Run Code Online (Sandbox Code Playgroud)
网址是这样的:
/users/auth/google/callback?_method=post&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=id_res&openid.op_endpoint=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fud&openid.response_nonce=2012-04-16T12%3A25%3A49Z_v1fNngSQJaHBQ&openid.return_to=http%3A%2F%2Fdev.myapp.me%3A3000%2Fusers%2Fauth%2Fgoogle%2Fcallback%3F_method%3Dpost&openid.assoc_handle=AMlYA9Urw_lYamPphTSdQ9a6DU0Ez0y5RaDDM78qPL7Xgm77nMpJiB85&openid.signed=op_endpoint%2Cclaimed_id%2Cidentity%2Creturn_to%2Cresponse_nonce%2Cassoc_handle%2Cns.ext1%2Cext1.mode%2Cext1.type.ext5%2Cext1.value.ext5%2Cext1.type.ext8%2Cext1.value.ext8%2Cext1.type.ext2%2Cext1.value.ext2&openid.sig=2FPjo7U1e%2Fde248XpUgjQLduNAM%3D&openid.identity=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3DAItOawk1F5U6x_-kJnydjoww5haU41tquh1Zl2c&openid.claimed_id=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3DAItOawk1F5U6x_-kJnydjoww5haU41tquh1Zl2c&openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ext1.mode=fetch_response&openid.ext1.type.ext5=http%3A%2F%2Faxschema.org%2FnamePerson%2Ffirst&openid.ext1.value.ext5=Some_User&openid.ext1.type.ext8=http%3A%2F%2Faxschema.org%2Fcontact%2Femail&openid.ext1.value.ext8=some_email%40gmail.com&openid.ext1.type.ext2=http%3A%2F%2Faxschema.org%2FnamePerson%2Flast&openid.ext1.value.ext2=Some_User
Run Code Online (Sandbox Code Playgroud)
所以我需要的所有数据都在URL中,但是设计/ omniauth没有抓住它(显然这就是为什么它调用'failure'方法而不是我的回调).我不知道它是否可以通过'params'数组访问,或者是什么.
我对这个?_method=post部分也很感兴趣,因为对我网站的所有请求都是GET请求.也许这只是意味着omniauth对谷歌的请求是POST.
有什么想法吗?
嗨,我正在学习如何使用omniauth作为ember应用程序的后端.
当我运行我的应用程序时,我得到下面提到的erroe OmniAuth :: NoSessionError - 你必须提供一个会话来使用OmniAuth
在resue rails上我的应用程序在下面的行停止.
172: def call!(env) # rubocop:disable CyclomaticComplexity
173: unless env['rack.session']
174: error = OmniAuth::NoSessionError.new('You must provide a session to use OmniAuth.')
=> 175: fail(error)
176: end
177:
Run Code Online (Sandbox Code Playgroud)
配置/初始化器/色器件
Devise.setup do |config|
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
require 'devise/orm/active_record'
config.case_insensitive_keys = [ :email ]
config.strip_whitespace_keys = [ :email ]
config.http_authenticatable = true
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 10
config.reconfirmable = true
config.expire_all_remember_me_on_sign_out = true
config.password_length = 8..128
config.reset_password_within = 6.hours
config.http_authenticatable_on_xhr …Run Code Online (Sandbox Code Playgroud) 我正在使用Doorkeeper作为我的Rails应用程序,我正在尝试这样做,当用户从门卫提供商退出时,用户将自动从所有应用程序注销.
默认情况下,当用户从应用程序注销时,他仍将在门卫提供商应用程序中登录.
这是我的门卫提供商的会话控制器.
class SessionsController < ApplicationController
def new
redirect_to root_path if current_user
session[:return_to] = params[:return_to] if params[:return_to]
end
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
if session[:return_to]
redirect_to session[:return_to]
session[:return_to] = nil
else
redirect_to root_path
end
else
flash.now.alert = "Email or password is invalid"
render "new"
end
end
def destroy
session[:user_id] = nil
flash[:alert] = "Sign Out successfully"
redirect_to new_session_path
end
end
Run Code Online (Sandbox Code Playgroud)
这是我的一个应用程序的会话控制器:
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
user = …Run Code Online (Sandbox Code Playgroud) omniauth ×10
ruby-on-rails ×10
devise ×6
facebook ×2
oauth-2.0 ×2
ruby ×2
doorkeeper ×1
rubygems ×1