带有Devise的raails,omniauth-google-oauth2和omniauth-linkedin-oauth2身份验证失败

时间:2016-12-03 04:47:12

标签: ruby-on-rails devise omniauth omniauth-google-oauth2 omniauth-linkedin

我正在使用omniauth-oauth2omniauth-google-oauth2omniauth-linkedin-oauth2omniauth-facebookomniauth-twitter宝石来验证我在aws ec2中托管的基本rails应用。 Facebook和Twitter身份验证工作正常,但使用Linkedin和google +进行身份验证时,正在呈现消息"未找到。身份验证passthru。" Facebook和Twitter工作正常。请帮我解决这个问题。任何帮助都是高度赞赏的。

先谢谢。

的Gemfile

ruby '2.3.1'
gem 'devise', '~> 4.2'
gem 'koala', '~> 2.4'
gem 'linkedin', '~> 1.1'
gem 'omniauth-oauth2', '~> 1.4'
gem 'omniauth-facebook'
gem 'omniauth-google-oauth2'
gem 'omniauth-twitter'
gem 'omniauth-linkedin-oauth2', '~> 0.1.5'

devise.rb

config.omniauth :facebook, "356781xxxxx", "1686997c451aecfd12dc7bxxxxxx",
                scope: 'email', info_fields: 'email',
                callback_url: "http://ec2-xx-xxx-xx-xx.us-west-   2.compute.amazonaws.com/users/auth/facebook/callback"
config.omniauth :twitter, "HnA4m6IzaZ1haT9nxxxxxxx", "SsL6TiWFLkKDWnta5zRek7YBvwfPBfMEiNYWRVxxxxxxxxxxx",
                callback_url: "http://ec2-xx-xxx-xx-xx.us-west-  2.compute.amazonaws.com/users/auth/twitter/callback"
config.omniauth :google_oauth2,"115059498414-  5fj2in117vueg4a1tdg52xxxxxxxxx.apps.googleusercontent.com","
                ZbPzUjSKpYRTmxxxxxxx",
                {
                  :name => "google",
                  :scope => "email, profile, plus.me",
                  :prompt => "select_account",
                  :image_aspect_ratio => "square",
                  :info_fields => "id,name,link",
                  :image_size => 50
                }
require "omniauth-linkedin-oauth2"
config.omniauth :linkedin, "811sfhxxxxxx","Pe2wtfRbxxxxx",:scope => 'r_fullprofile r_emailaddress'

用户/ omniauth_callbacks_controller.rb

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
   skip_before_action :verify_authenticity_token

   def sign_in_with(provider_name)
     @user = User.from_omniauth(request.env["omniauth.auth"])
     sign_in_and_redirect @user, :event => :authentication
     set_flash_message(:notice, :success, :kind => provider_name) if is_navigational_format?
   end

   def facebook
     sign_in_with "Facebook"
   end

   def linkedin
     sign_in_with "LinkedIn"
   end

   def twitter
     sign_in_with "Twitter"
   end

   def google_oauth2
     sign_in_with "Google"
   end

   def developer
     sign_in_with "Developer"
   end
end

user.rb

class User < ActiveRecord::Base
  devise :rememberable, :trackable, :omniauthable,
         :omniauth_providers => [:twitter,:facebook,
                                 :linkedin_oauth2, :google_oauth2,
                                 *(:developer if Rails.env.development?)]

  def self.from_omniauth(auth)
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
      user.email = auth.info.email
    end
  end
end

的routes.rb

Rails.application.routes.draw do
  devise_for :users, :controllers => {
  :omniauth_callbacks => "users/omniauth_callbacks"
   }
  devise_scope :user do
    get 'sign_in', :to => 'devise/sessions#new', :as => :new_user_session
    delete 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
  end

  root 'home#index'
end

回调google开发者帐户中我的应用网站的网址:

   Authorized JavaScript origins : http://ec2-xx-xxx-xx-xx.us-west
   Authorized redirect URIs : ec2-xx-xxx-xx-xx.us-west/users/auth/google/callback

也试过

   ec2-xx-xxx-xx-xx.us-west/users/auth/google_oauth2/callback

在Linkedin开发者帐户中回访我的应用网站的网址:

      OAuth 2.0 Authorized Redirect URLs:
      ec2-xx-xxx-xx-xx.us-west/users/auth/linkedin/callback
      ec2-xx-xxx-xx-xx.us-west/users/auth/linkedin_oauth2/callback

甚至尝试使用OAuth 1.0a默认&#34;接受&#34;重定向网址:

   ec2-xx-xxx-xx-xx.us-west-/users/auth/linkedin/callback

0 个答案:

没有答案