Added defaults for omniauth

This commit is contained in:
jfederico 2017-08-14 21:08:56 +00:00
parent ea5c78db47
commit 5a5693cb33
1 changed files with 11 additions and 13 deletions

View File

@ -1,24 +1,22 @@
Rails.application.config.providers = [:google, :twitter, :ldap]
Rails.application.config.omniauth_google = ENV['GOOGLE_OAUTH2_ID'].present?
Rails.application.config.omniauth_google = ENV['GOOGLE_OAUTH2_ID'].present? && ENV['GOOGLE_OAUTH2_SECRET'].present?
Rails.application.config.omniauth_twitter = ENV['TWITTER_ID'].present?
Rails.application.config.omniauth_twitter = ENV['TWITTER_ID'].present? && ENV['TWITTER_SECRET'].present?
Rails.application.config.omniauth_ldap = ENV['LDAP_SERVER'].present?
Rails.application.config.omniauth_ldap = ENV['LDAP_SERVER'].present? && ENV['LDAP_UID'].present? && ENV['LDAP_BASE'].present? && ENV['LDAP_BIND_DN'].present? && ENV['LDAP_PASSWORD'].present?
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ENV['TWITTER_ID'], ENV['TWITTER_SECRET']
provider :google_oauth2,
ENV['GOOGLE_OAUTH2_ID'],
ENV['GOOGLE_OAUTH2_SECRET'],
scope: ENV['ENABLE_YOUTUBE_UPLOADING'] == 'true' ? ['profile', 'email', 'youtube', 'youtube.upload'] : ['profile', 'email'] ,
access_type: 'online',
provider :google_oauth2, ENV['GOOGLE_OAUTH2_ID'], ENV['GOOGLE_OAUTH2_SECRET'],
scope: ENV['ENABLE_YOUTUBE_UPLOADING'] && ENV['ENABLE_YOUTUBE_UPLOADING'] == "true" ? ['profile', 'email', 'youtube', 'youtube.upload'] : ['profile', 'email'] ,
access_type: 'online',
name: 'google',
hd: ENV['GOOGLE_OAUTH2_HD'].blank? ? nil : ENV['GOOGLE_OAUTH2_HD']
hd: ENV['GOOGLE_OAUTH2_HD']
provider :ldap,
host: ENV['LDAP_SERVER'],
port: ENV['LDAP_PORT'],
method: ENV['LDAP_METHOD'].present? ? ENV['LDAP_METHOD'].to_sym : :plain,
port: ENV['LDAP_PORT'] || '389',
method: (ENV['LDAP_METHOD'] || 'plain').to_sym,
allow_username_or_email_login: true,
uid: ENV['LDAP_UID'],
base: ENV['LDAP_BASE'],
@ -37,10 +35,10 @@ OmniAuth.config.on_failure = Proc.new { |env|
module OmniAuthLDAPExt
def request_phase
rel_root = ENV['RELATIVE_URL_ROOT'].present? ? ENV['RELATIVE_URL_ROOT'] : '/b'
rel_root = '' if Rails.env == 'development'
@callback_path = nil
path = options[:callback_path]
options[:callback_path] = "#{rel_root}/auth/ldap/callback"