标签: omniauth

rails omniauth facebook扩展许可

我读过omniauth oauth rdoc

  @consumer = OAuth::Consumer.new(key, secret, {
    :site               => "http://term.ie",
    :scheme             => :header,
    :http_method        => :post,
    :request_token_path => "/oauth/example/request_token.php",
    :access_token_path  => "/oauth/example/access_token.php",
    :authorize_path     => "/oauth/example/authorize.php"
   })
Run Code Online (Sandbox Code Playgroud)

没有范围如

https://graph.facebook.com/oauth/authorize?
    client_id=...&
    redirect_uri=http://www.example.com/callback&
    scope=user_photos,user_videos,publish_stream
Run Code Online (Sandbox Code Playgroud)

我该如何添加一个?我现在试图覆盖oauth ...有没有人有更好的解决方案?

ruby-on-rails oauth oauth-ruby facebook-graph-api omniauth

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

Facebook应用程序 - 通过omniauth登录 - OAuthException 191

我面临的问题是:

  "error": {
      "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
      "type": "OAuthException",
      "code": 191
   }
Run Code Online (Sandbox Code Playgroud)

我成立了我的应用程序所需的密钥和标记,在Facebook的开发中心我设置Site URL:http://127.0.0.1:3001和我收到上述错误.此外,我试图建立App Namespace:http://127.0.0.1:3001,但我得到不好的地址格式错误.当我试着填写他App Domain:并设置有我的本地主机,再为格式错误的错误...

使用localhost的fabebook应用程序的正确配置是什么?

facebook ruby-on-rails facebook-graph-api omniauth

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

使用出站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
查看次数

OmniAuth路由错误,没有路由匹配

我正在通过Ryan Bates railscast#235 OmniAuth第1部分,使用OmniAuth gem允许用户使用Twitter或Facebook以及更高版本的Google Apps登录我的网络应用程序.

现在我遇到了这个错误

Routing Error

No route matches [GET] "/auth/twitter"
Run Code Online (Sandbox Code Playgroud)

我已经正确设置了routes.rb文件来处理auth回调提供程序匹配,如下所示:

  match "/auth/:provider/callback" => "authentications#create"
Run Code Online (Sandbox Code Playgroud)

当我链接到localhost:3000/auth/twitter时,我收到此错误.Bates在他的Railscast -07:36.

什么可能解决这个问题?这会是routes.rb的问题吗?还是omniauth.rb?

我们的omniauth.rb看起来像这样:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, 'OURCONSUMERKEY', 'OURCONSUMERSECRET'
  provider :twitter,  'OURCONSUMERKEY', 'OURCONSUMERSECRET'
end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails omniauth

14
推荐指数
3
解决办法
7589
查看次数

"CSRF检测到"与Omniauth和Google合作

我得到了这个

OmniAuth :: Strategies :: OAuth2 ::/auth/google/callback中的CallbackError csrf_detected | CSRF检测到

我的代码:

require 'sinatra'
require "sinatra/json"
require "sinatra/config_file"
require 'omniauth-oauth2'
require 'omniauth-google-oauth2'

use Rack::Logger

config_file "config/app_config.yml"
use Rack::Session::Cookie, secret: '5fb7w345y3489f523y4h'

configure do
  enable :sessions
end

use OmniAuth::Builder do
  provider :google_oauth2, settings.google[:client_id], settings.google[:secret],
    {
      :scope => "userinfo.profile",
      :access_type => "offline",
      :prompt => "select_account consent",
      :name => "google"
    }
end

get '/list' do
  json get_list
end

get '/' do
  %Q|<a href='/auth/google'>Sign in with Google</a>|
end

get '/auth/:name/callback' do
  @auth = request.env['omniauth.auth']
  @auth.inspect
end …
Run Code Online (Sandbox Code Playgroud)

ruby sinatra oauth-2.0 omniauth

14
推荐指数
3
解决办法
2万
查看次数

如何使用Rails,Omniauth和Rspec对Facebook登录操作进行单元测试

之前我问了一个类似的问题,但我想我已经超过了原来的错误.无论如何,我有一个新的乐趣失败,我正在试图弄清楚(注意讽刺).这是我的失败:

1) SessionsController#facebook_login should be valid
   Failure/Error: get :facebook_login
   NoMethodError:
     undefined method `slice' for nil:NilClass
   # ./app/models/user.rb:19:in `from_omniauth'
   # ./app/controllers/sessions_controller.rb:22:in `facebook_login'
   # ./spec/controllers/sessions_controller_spec.rb:96:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

sessions_controller_spec.rb

describe '#facebook_login' do

  before(:each) do
    valid_facebook_login_setup
    request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
    get :facebook_login
  end

  it "should be valid" do
    expect(response).to be_success
  end

  it "should set user_id" do
    expect(session[:user_id]).to be_true
  end
end
Run Code Online (Sandbox Code Playgroud)

sessions_controller.rb

def facebook_login
  if request.env['omniauth.auth']
    user = User.from_omniauth(env['omniauth.auth'])
    session[:user_id] = user.id
    redirect_back_or root_path
  else
    redirect_to root_path
  end
end
Run Code Online (Sandbox Code Playgroud)

omn​​iauth_test_helper.rb

module OmniAuthTestHelper …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails omniauth

14
推荐指数
1
解决办法
5613
查看次数

OmniAuth使用谷歌oauth 2战略范围失败

我正在使用OmniAuthgoogle-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)

有什么我缺少的东西或我应该改变的东西?

ruby-on-rails google-calendar-api oauth-2.0 omniauth

13
推荐指数
2
解决办法
7205
查看次数

使用Devise和Omniauth编辑用户

我正在通过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)

ruby-on-rails devise omniauth ruby-on-rails-3.2

13
推荐指数
2
解决办法
5372
查看次数

"omniauth-twitter"电子邮件ID不是来自ruby on rails的twitter

我正在使用omn​​iauth-twitter gem在我的rails应用程序中启用Twitter登录.这是我的代码......

gemfile -

gem 'omniauth', '~> 1.1.1'
gem 'omniauth-twitter'
Run Code Online (Sandbox Code Playgroud)

routes.rb -

 match '/auth/twitter/callback', to: 'users#twitter_login'
 match 'auth/failure', to: 'static_pages#home'
Run Code Online (Sandbox Code Playgroud)

User_controller.rb -

     def twitter_login
       auth = request.env['omniauth.auth'] 
       authentication = Authentication.find_by_provider_and_uid(auth['provider'],auth['uid'])
       if authentication
          sign_in authentication.user
          redirect_to root_url
       else
         if(User.where(:email => auth['extra']['raw_info']['email']).exists?)
            flash[:notice] = "You already have account in ibetter"
            redirect_to root_url        
         else
            user = User.new
            user.apply_omniauth(auth)        
            if user.save(:validate => false)     
              sign_in user           
              flash[:notice] = "Welcome to Ginfy"          
              redirect_to root_url
            else
              flash[:error] = "Error while creating a user account. Please try …
Run Code Online (Sandbox Code Playgroud)

ruby twitter ruby-on-rails omniauth ruby-on-rails-3

13
推荐指数
2
解决办法
4862
查看次数

自动加载常量用户时检测到循环依赖性

我已经按照本教程(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)

ruby rubygems ruby-on-rails devise omniauth

13
推荐指数
2
解决办法
3万
查看次数