标签: omniauth

OmniAuth Google OpenID WEBrick :: HTTPStatus :: RequestURITooLarge

我使用OmniAuth允许用户使用他们的Google OpenID帐户登录.当我尝试使用WEBrick以开发模式登录时,我收到WEBrick :: HTTPStatus :: RequestURITooLarge错误.当我将它部署到我的rails主机时,它工作正常.我应该使用不同的Web服务器而不是WEBrick吗?

ruby-on-rails webrick omniauth ruby-on-rails-3

17
推荐指数
3
解决办法
3803
查看次数

":event =>:authentication"有什么作用?

这实际上是一个非常简单的问题,但我似乎找不到答案.在GithubOmniauth概述中,实际上有一个解释,但我没有得到它:

We pass the :event => :authentication to the sign_in_and_redirect method
to force all authentication callbacks to be called.
Run Code Online (Sandbox Code Playgroud)

我已经使用与此类似的操作进行身份验证:

def facebook
  authenticator = UserAuthenticator.new(request.env["omniauth.auth"], current_user)

  if authenticator.user_authenticated?
    sign_in_and_redirect authenticator.user, :event => :authentication
  else
    session["devise.oauth_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end
Run Code Online (Sandbox Code Playgroud)

我真正想知道的是有什么好处:event => :authentication

devise omniauth ruby-on-rails-3

17
推荐指数
2
解决办法
8732
查看次数

Rails:在Omniauth使用Devise登录后从Facebook检索图像

我使用这些说明设置Facebook登录与Devise和omniauth https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

Devise wiki提供了从存储在此变量中的哈希获取facebook信息的一些说明.request.env['omniauth.auth']请参阅底部的哈希.

例如,Devise wiki为User.rb模型提供了这两种方法

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
  data = access_token.extra.raw_info
  if user = User.where(:email => data.email).first
    user
  else # Create a user with a stub password. 
    User.create!(:email => data.email, :password => Devise.friendly_token[0,20]) 
  end
end

def self.new_with_session(params, session)
    super.tap do |user|
      if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
        user.email = data["email"]

      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

因此,使用下面的哈希,我将以下两个方法添加到以获取名称和图像

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
  data = access_token.extra.raw_info
  if user = User.where(:email => data.email).first
    user
  else # Create a user with a stub …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails facebook-graph-api omniauth

17
推荐指数
1
解决办法
1万
查看次数

OmniAuth拒绝回电

当我在Rails 3应用程序中使用OmniAuth启动登录过程时,如果我在提供者的页面上取消,我将被发送回一个类似于以下内容的URL:

http://example.com/auth/twitter/callback?denied=aUho....
Run Code Online (Sandbox Code Playgroud)

我的应用程序抛出一个500,我可以看到它是OAuth :: Unauthorized:401 Unauthorized,没有触及我的任何控制器操作.

堆栈跟踪是我在我的计算机中重现它时:

oauth (0.4.6) lib/oauth/consumer.rb:216:in `token_request'
oauth (0.4.6) lib/oauth/consumer.rb:136:in `get_request_token'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:29:in `request_phase'
omniauth-twitter (0.0.11) lib/omniauth/strategies/twitter.rb:50:in `request_phase'
omniauth (1.1.0) lib/omniauth/strategy.rb:207:in `request_call'
omniauth (1.1.0) lib/omniauth/strategy.rb:174:in `call!'
omniauth (1.1.0) lib/omniauth/strategy.rb:157:in `call'
omniauth (1.1.0) lib/omniauth/strategy.rb:177:in `call!'
omniauth (1.1.0) lib/omniauth/strategy.rb:157:in `call'
omniauth (1.1.0) lib/omniauth/builder.rb:48:in `call'
sass (3.1.19) lib/sass/plugin/rack.rb:54:in `call'
warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
warden (1.1.1) lib/warden/manager.rb:34:in `catch'
warden (1.1.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.6) …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails omniauth

17
推荐指数
2
解决办法
4519
查看次数

请求的资源上不存在"Access-Control-Allow-Origin"标头

我在AngularJS上使用omniauth-facebook并且CORS无法正常工作.

我的omniauth.rb是

Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook,"xxxxx", "xxxxx",
:scope => 'email,user_birthday,read_stream', :display => 'popup'

end
Run Code Online (Sandbox Code Playgroud)

如果我将它用作rails应用程序和请求,一切正常.但是当我尝试通过Angular JS调用'http:\ localhost:3000\users\auth\facebook"时

$http.get('/users/auth/facebook').success(function(data, status, headers, config) {
            console.log("back in success");
            }).
            error(function(data, status, headers, config) {

            });
    }
Run Code Online (Sandbox Code Playgroud)

我在JS控制台中看到以下错误

XMLHttpRequest无法加载 https://www.facebook.com/dialog/oauth?client_id=xxxx&display=popup ... thday%2Cread_stream&state = 3352c1924bdbc9277f7b1070c38d67acf79b529f198323cb.请求的资源上不存在"Access-Control-Allow-Origin"标头.'http://localhost:3000'因此不允许原点访问.

(该控制台中的网址未完全显示)

我添加了以下行

config.middleware.insert_before Warden::Manager, Rack::Cors
Run Code Online (Sandbox Code Playgroud)

但这也行不通.

什么是最好的方式或如何覆盖OmniAuth的标头?

我正在使用Angularjs和gem devise,omniauth-facebook

ruby-on-rails omniauth ruby-on-rails-3.2 angularjs

17
推荐指数
1
解决办法
3万
查看次数

使用google_oauth2获取"错误:redirect_uri_mismatch"

网址似乎正确(昨天上次更新):

在此输入图像描述

文件也是:

omn​​iauth.rb:

provider :google_oauth2, 'MY_CLIENT_ID.apps.googleusercontent.com', 'MY_CLIENT_SECRET',
           :scope => 'https://mail.google.com/mail/feed/atom/'

Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:3000/auth/google_oauth2/callback did not match a registered redirect URI
Run Code Online (Sandbox Code Playgroud)

header.html.erb

<li><%= link_to "Sign in with Google", "auth/google_oauth2" %></li>
Run Code Online (Sandbox Code Playgroud)

routes.rb中:

match '/auth/:provider/callback', to: 'sessions#omniauth_create'
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个:

> Error: redirect_uri_mismatch The redirect URI in the request:
> http://localhost:3000/auth/google_oauth2/callback did not match a
> registered redirect URI
Run Code Online (Sandbox Code Playgroud)

(Twitter和Facebook OmniAuth工作正常)

不确定是什么问题.有什么好处可以解决这个问题吗?

编辑

我将URI更改为http...:

在此输入图像描述

但仍然得到同样的错误.

ruby-on-rails omniauth

16
推荐指数
1
解决办法
1万
查看次数

Oauth2 Instagram API"重定向URI与注册的重定向URI不匹配"

我正在开发一个处于开发模式的Rails应用程序,它可以注册omniauth.

主持人是

http://localhost:3000/
Run Code Online (Sandbox Code Playgroud)

我正在使用宝石:

gem 'omniauth'
gem 'omniauth-foursquare'
gem 'omniauth-instagram'
Run Code Online (Sandbox Code Playgroud)

当我通过Foursquare注册omniauth时,根本没有问题.所有设置都是正确的,我在Foursquare开发人员设置中的redirect_uri等于主机(localhost:3000)

但是,如果我在Instagram客户端管理器*中填写完全相同的redirect_uri(localhost:3000).Instagram给了我这个:

{
 "code": 400,
 "error_type": "OAuthException",
 "error_message": "Redirect URI does not match registered             redirect URI"
}
Run Code Online (Sandbox Code Playgroud)

基于此URL:

https://instagram.com/oauth/authorize?response_type=code&client_id=<ID>&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Finstagram%2Fcallback&state=18415adf24dd97873e61094f67c0fb7a94857fedf93e9d2e&scope=basic
Run Code Online (Sandbox Code Playgroud)

* 在此输入图像描述

根据Instagram,我做错了什么,应该如何解决?

ruby-on-rails oauth-2.0 omniauth instagram

16
推荐指数
3
解决办法
6万
查看次数

在Rails 3.2中使用OmniAuth-Twitter需要OAuth :: Unauthorized 401授权

我已经在StackOverFlow中实现了几种不同的策略,但到目前为止,似乎都没有影响抛出的错误:

OAuth::Unauthorized 401 Authorization Required

我正在关注Ryan Bates的RC#241,并点击"用Twitter登录"这一点,我收到了错误消息.我继续将响应路由添加到routes.rb此处列出的文件中:

routes.rb:

match 'auth/twitter/callback', to: 'user#update'
Run Code Online (Sandbox Code Playgroud)

认为错误可能是由回调函数引起的.同样的错误.看看我的dev.log节目:

Started GET "/auth/twitter" for 127.0.0.1 at 2014-09-16 18:52:08 -0600
(twitter) Request phase initiated.

OAuth::Unauthorized (401 Authorization Required):
oauth (0.4.7) lib/oauth/consumer.rb:216:in `token_request'
oauth (0.4.7) lib/oauth/consumer.rb:136:in `get_request_token'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:29:in `request_phase'
omniauth-twitter (1.0.1) lib/omniauth/strategies/twitter.rb:60:in `request_phase'
omniauth (1.2.2) lib/omniauth/strategy.rb:215:in `request_call'
omniauth (1.2.2) lib/omniauth/strategy.rb:183:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.2.2) lib/omniauth/builder.rb:59:in `call'
...
script/rails:6:in `require'
script/rails:6:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Run Code Online (Sandbox Code Playgroud)

所以我知道问题在于Twitter的认证问题.必须是KEY和SECRET,对吧? …

twitter omniauth ruby-on-rails-3

16
推荐指数
1
解决办法
1万
查看次数

Rails Google Client API - 无法为访问令牌交换刷新令牌

在我的机器上遇到一些SSL问题之后,我仍然试图通过Google Ruby Client API访问用户的Blogger帐户.我正在使用以下内容:

  • Rails 3.2.3
  • Ruby 1.9.3
  • oauth2(0.8.0)
  • omn​​iauth(1.1.1)
  • omn​​iauth-google-oauth2(0.1.13)
  • google-api-client(0.4.6)

我可以在身份验证时通过Google API成功验证用户身份并访问他们的博客.当用户登录时,我会存储access_tokenrefresh_token从Google收到.一切都很好,直到access_token过期.我正在尝试构建交换refresh_token新功能的功能access_token,但不断遇到问题.以客户端文档为例,这是我正在使用的代码:

  client = Google::APIClient.new
  token_pair = auth.oauth_token   # access_token and refresh_token received during authentication

  # Load the access token if it's available
  if token_pair  
    client.authorization.update_token!(token_pair.to_hash)
  end            

  # Update access token if expired
  if client.authorization.refresh_token && client.authorization.expired?
    client.authorization.fetch_access_token!
  end

  blogger = client.discovered_api('blogger', 'v3')
  result = client.execute(
      api_method: blogger.blogs.list_by_user,
      parameters: {'userId' => "self", 'fields' => …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails access-token oauth-2.0 omniauth google-api-client

15
推荐指数
2
解决办法
7802
查看次数

使用出站http代理的Rails Omniauth

我们试图在http代理后面的Rails应用程序中使用linkedin-omniauth gem.

我已经尝试了所有我能找到的omniauth使用代理,但我无法让它工作.

下面的帖子建议使用:

provider :linkedin, 'xxx', 'xxx', {
  :client_options => {
    :proxy => ENV["HTTP_PROXY"] || ENV["http_proxy"]
  }
}
Run Code Online (Sandbox Code Playgroud)

哪个对我不起作用,我在源代码中没有提到"代理".我也试过硬编码代理.没有成功.

这个SO帖子对我也不起作用.

我还用代理创建了net :: http的初始化程序.这也行不通.我已经在我的shell和bashrc中导出了代理.在/ etc/environment中.没有什么工作.

如何使用omniauth来使用出站代理?

---更新---

虽然下面接受的答案确实适用于Linkedin Oauth,但现在大多数宝石都依赖于Oauth2.这消除了Net :: HTTP并引入了Faraday,它对代理/连接设置的规则有一个单独的设置:

https://github.com/simonmorley/oauth2/blob/master/lib/oauth2/client.rb#L36

为了让代理使用后来的宝石(包括流行的Facebook,Google,Github检查他们依赖的宝石),您需要在初始化程序中使用以下内容:

  provider :foursquare, 'xxx', 'xxx', {
    :client_options => {
      :connection_opts => {
        :proxy => "http://127.0.0.1:3128"
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

proxy ruby-on-rails omniauth

15
推荐指数
1
解决办法
1168
查看次数