GRN2-107: Add office365 auth (#616)

* add office365 auth

* Delete conflicting file
This commit is contained in:
shawn-higgins1 2019-07-09 13:54:15 -04:00 committed by Jesus Federico
parent 40b05b1626
commit fc18976b6d
22 changed files with 53 additions and 43 deletions

View File

@ -44,7 +44,7 @@ gem 'bcrypt', '~> 3.1.7'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-google-oauth2'
gem 'omniauth-microsoft-office365', '~> 0.0.7'
gem 'omniauth-bn-office365', git: 'https://github.com/blindsidenetworks/omniauth-azure-ad.git'
gem 'omniauth-ldap'
gem 'omniauth-bn-launcher', '~> 0.1.0'

View File

@ -1,3 +1,11 @@
GIT
remote: https://github.com/blindsidenetworks/omniauth-azure-ad.git
revision: c0c7d4dfb4fa4e66986dba6b436a924d83e48377
specs:
omniauth-bn-office365 (1.0.0)
omniauth (>= 1.3.2)
omniauth-oauth2 (>= 1.5.0)
GEM
remote: https://rubygems.org/
specs:
@ -155,9 +163,6 @@ GEM
omniauth (~> 1.0)
pyu-ruby-sasl (~> 0.0.3.2)
rubyntlm (~> 0.3.4)
omniauth-microsoft-office365 (0.0.7)
omniauth
omniauth-oauth2
omniauth-oauth (1.1.0)
oauth
omniauth (~> 1.0)
@ -341,9 +346,9 @@ DEPENDENCIES
mini_racer
omniauth
omniauth-bn-launcher (~> 0.1.0)
omniauth-bn-office365!
omniauth-google-oauth2
omniauth-ldap
omniauth-microsoft-office365 (~> 0.0.7)
omniauth-twitter
pagy
pg (~> 0.18)

View File

@ -123,7 +123,7 @@
}
}
.customBtn-microsoft_office365 {
.customBtn-office365 {
@extend .customBtn;
background: #f65314;

View File

@ -78,17 +78,23 @@ module SessionsHelper
end
def omniauth_options(env)
gl_redirect_url = (Rails.env.production? ? "https" : env["rack.url_scheme"]) + "://" + env["SERVER_NAME"] + ":" +
env["SERVER_PORT"]
user_domain = parse_user_domain(env["SERVER_NAME"])
env['omniauth.strategy'].options[:customer] = user_domain
env['omniauth.strategy'].options[:gl_redirect_url] = gl_redirect_url
env['omniauth.strategy'].options[:default_callback_url] = Rails.configuration.gl_callback_url
env['omniauth.strategy'].options[:checksum] = generate_checksum(user_domain, gl_redirect_url,
Rails.configuration.launcher_secret)
if env['omniauth.strategy'].options[:name] == "bn-launcher"
gl_redirect_url = (Rails.env.production? ? "https" : env["rack.url_scheme"]) + "://" + env["SERVER_NAME"] + ":" +
env["SERVER_PORT"]
user_domain = parse_user_domain(env["SERVER_NAME"])
env['omniauth.strategy'].options[:customer] = user_domain
env['omniauth.strategy'].options[:gl_redirect_url] = gl_redirect_url
env['omniauth.strategy'].options[:default_callback_url] = Rails.configuration.gl_callback_url
env['omniauth.strategy'].options[:checksum] = generate_checksum(user_domain, gl_redirect_url,
Rails.configuration.launcher_secret)
elsif env['omniauth.strategy'].options[:name] == "google"
set_hd(env, ENV['GOOGLE_OAUTH2_HD'])
elsif env['omniauth.strategy'].options[:name] == "office365"
set_hd(env, ENV['OFFICE365_HD'])
end
end
def google_omniauth_hd(env, hd)
def set_hd(env, hd)
hd_opts = hd.split(',')
env['omniauth.strategy'].options[:hd] =
if hd_opts.empty?

View File

@ -70,7 +70,7 @@ class User < ApplicationRecord
# Provider attributes.
def auth_name(auth)
case auth['provider']
when :microsoft_office365
when :office365
auth['info']['display_name']
else
auth['info']['name']
@ -97,7 +97,7 @@ class User < ApplicationRecord
when :twitter
auth['info']['image'].gsub("http", "https").gsub("_normal", "")
else
auth['info']['image'] unless auth['provider'] == :microsoft_office365
auth['info']['image']
end
end
end

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true
require 'office365'
# List of supported Omniauth providers.
Rails.application.config.providers = []
@ -10,19 +12,14 @@ Rails.application.config.omniauth_ldap = ENV['LDAP_SERVER'].present? && ENV['LDA
ENV['LDAP_PASSWORD'].present?
Rails.application.config.omniauth_twitter = ENV['TWITTER_ID'].present? && ENV['TWITTER_SECRET'].present?
Rails.application.config.omniauth_google = ENV['GOOGLE_OAUTH2_ID'].present? && ENV['GOOGLE_OAUTH2_SECRET'].present?
Rails.application.config.omniauth_microsoft_office365 = ENV['OFFICE365_KEY'].present? &&
ENV['OFFICE365_SECRET'].present?
Rails.application.config.omniauth_office365 = ENV['OFFICE365_KEY'].present? &&
ENV['OFFICE365_SECRET'].present?
# If LDAP is enabled, override and disable allow_user_signup.
Rails.application.config.allow_user_signup = false if Rails.application.config.omniauth_ldap
SETUP_PROC = lambda do |env|
provider = env['omniauth.strategy'].options[:name]
if provider == "google"
SessionsController.helpers.google_omniauth_hd env, ENV['GOOGLE_OAUTH2_HD']
else
SessionsController.helpers.omniauth_options env
end
SessionsController.helpers.omniauth_options env
end
# Setup the Omniauth middleware.
@ -59,10 +56,11 @@ Rails.application.config.middleware.use OmniAuth::Builder do
name: 'google',
setup: SETUP_PROC
end
if Rails.configuration.omniauth_microsoft_office365
Rails.application.config.providers << :microsoft_office365
if Rails.configuration.omniauth_office365
Rails.application.config.providers << :office365
provider :microsoft_office365, ENV['OFFICE365_KEY'], ENV['OFFICE365_SECRET']
provider :office365, ENV['OFFICE365_KEY'], ENV['OFFICE365_SECRET'],
setup: SETUP_PROC
end
end
end

View File

@ -155,7 +155,7 @@ ar:
password_different_notice: تأكيد كلمة المرور غير متطابق.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recording:
email: " البريد الإلكتروني للتسجيل"

View File

@ -284,7 +284,7 @@ de_DE:
password_different_notice: Passwortbestätigung ist nicht zutreffend.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recaptcha:
errors:

View File

@ -300,7 +300,7 @@ en:
password_different_notice: Password Confirmation does not match.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recaptcha:
errors:

View File

@ -284,7 +284,7 @@ es:
password_different_notice: La confirmación de password no coincide
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recaptcha:
errors:

View File

@ -284,7 +284,7 @@ es_MX:
password_different_notice: La confirmación de password no coincide
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recaptcha:
errors:

View File

@ -283,7 +283,7 @@ fa_IR:
password_different_notice: تاییدیه رمز عبور با رمز ارائه شده مطابقت ندارد.
provider:
google: گوگل
microsoft_office365: افیس 365
office365: افیس 365
twitter: توییتر
recaptcha:
errors:

View File

@ -155,7 +155,7 @@ fr:
password_different_notice: La confirmation du mot de passe ne correspond pas.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recording:
email: Envoyer l'enregistrement par Email

View File

@ -155,7 +155,7 @@ hi_IN:
password_different_notice: पासवर्ड की पुष्टि मेल नहीं खाती।
provider:
google: गूगल
microsoft_office365: ऑफिस 365
office365: ऑफिस 365
twitter: ट्विटर
recording:
email: ईमेल रिकॉर्डिंग

View File

@ -283,7 +283,7 @@ hu_HU:
password_different_notice: A két új jelszó eltér egymástól.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recaptcha:
errors:

View File

@ -284,7 +284,7 @@ it:
password_different_notice: La conferma della password non coincide.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recaptcha:
errors:

View File

@ -155,7 +155,7 @@ pt:
password_different_notice: A Confirmação de Senha não corresponde a Senha inserida acima.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recording:
email: Enviar Gravação por E-mail

View File

@ -155,7 +155,7 @@ pt_BR:
password_different_notice: A confirmação de senha não confere.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recording:
email: Enviar link da gravação por e-mail

View File

@ -131,7 +131,7 @@ ru_RU:
password_different_notice: Подтверждение пароля не совпадает.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recording:
email: Отправить ссылку на запись

View File

@ -219,7 +219,7 @@ vi_VN:
password_different_notice: Xác nhận mật khẩu không khớp.
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recaptcha:
errors:

View File

@ -283,7 +283,7 @@ zh_CN:
password_different_notice: 两次新密码不一致。
provider:
google: Google
microsoft_office365: Office 365
office365: Office 365
twitter: Twitter
recaptcha:
errors:

View File

@ -47,6 +47,7 @@ TWITTER_SECRET=
#
OFFICE365_KEY=
OFFICE365_SECRET=
OFFICE365_HD=
# LDAP Login Provider (optional)
#