Omniauth

首先選擇你的身份驗證策略並將其新增到你的 Gemfile。你可以在此處找到策略列表: https//github.com/intridea/omniauth/wiki/List-of-Strategies

gem 'omniauth-github', :github => 'intridea/omniauth-github'
gem 'omniauth-openid', :github => 'intridea/omniauth-openid'

你可以將其新增到 rails 中介軟體,如下所示:

Rails.application.config.middleware.use OmniAuth::Builder do
  require 'openid/store/filesystem' 
  provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
  provider :openid, :store => OpenID::Store::Filesystem.new('/tmp')
end

預設情況下,OmniAuth 會將/auth/:provider 新增到你的路線中,你可以從這些路徑開始。

預設情況下,如果出現故障,omniauth 將重定向到/auth/failure