1

我正在使用omniauth-oauth2, omniauth-google-oauth2, omniauth-linkedin-oauth2, omniauth-facebook, omniauth-twittergems 对托管在 aws ec2 中的基本 rails 应用程序进行身份验证。Facebook 和 Twitter 身份验证工作正常,但使用 Linkedin 和 google+ 进行身份验证时呈现消息“未找到。身份验证通路”。Facebook 和 Twitter 工作正常。请帮助我解决问题。非常感谢任何帮助。

提前致谢。

宝石文件

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'

设计.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

用户.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

路线.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

谷歌开发者帐户中我的应用程序站点的回调 URL:

   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开发者帐户中我的应用程序站点的回调URL:

      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 默认“接受”重定向 URL:

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

0 回答 0