From fc18976b6d002a1303f6a59a96921aa31aa203a5 Mon Sep 17 00:00:00 2001 From: shawn-higgins1 <23224097+shawn-higgins1@users.noreply.github.com> Date: Tue, 9 Jul 2019 13:54:15 -0400 Subject: [PATCH] GRN2-107: Add office365 auth (#616) * add office365 auth * Delete conflicting file --- Gemfile | 2 +- Gemfile.lock | 13 +++++++++---- app/assets/stylesheets/main.scss | 2 +- app/helpers/sessions_helper.rb | 24 +++++++++++++++--------- app/models/user.rb | 4 ++-- config/initializers/omniauth.rb | 20 +++++++++----------- config/locales/ar.yml | 2 +- config/locales/de_DE.yml | 2 +- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- config/locales/es_MX.yml | 2 +- config/locales/fa_IR.yml | 2 +- config/locales/fr.yml | 2 +- config/locales/hi_IN.yml | 2 +- config/locales/hu_HU.yml | 2 +- config/locales/it.yml | 2 +- config/locales/pt.yml | 2 +- config/locales/pt_BR.yml | 2 +- config/locales/ru_RU.yml | 2 +- config/locales/vi_VN.yml | 2 +- config/locales/zh_CN.yml | 2 +- sample.env | 1 + 22 files changed, 53 insertions(+), 43 deletions(-) diff --git a/Gemfile b/Gemfile index e32bf501..8edc5c0f 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 9fd50cf3..1de91bf7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index dcd6dacd..42e41209 100755 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -123,7 +123,7 @@ } } -.customBtn-microsoft_office365 { +.customBtn-office365 { @extend .customBtn; background: #f65314; diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb index df1fa19d..b95dd302 100644 --- a/app/helpers/sessions_helper.rb +++ b/app/helpers/sessions_helper.rb @@ -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? diff --git a/app/models/user.rb b/app/models/user.rb index 2966e22e..f7af9a35 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index e3e54a78..4d4ae321 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -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 diff --git a/config/locales/ar.yml b/config/locales/ar.yml index 9907b61c..9c46a929 100644 --- a/config/locales/ar.yml +++ b/config/locales/ar.yml @@ -155,7 +155,7 @@ ar: password_different_notice: تأكيد كلمة المرور غير متطابق. provider: google: Google - microsoft_office365: Office 365 + office365: Office 365 twitter: Twitter recording: email: " البريد الإلكتروني للتسجيل" diff --git a/config/locales/de_DE.yml b/config/locales/de_DE.yml index c85614dd..f1dd1b55 100644 --- a/config/locales/de_DE.yml +++ b/config/locales/de_DE.yml @@ -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: diff --git a/config/locales/en.yml b/config/locales/en.yml index a933429c..f821a047 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/config/locales/es.yml b/config/locales/es.yml index e726de20..aaf68999 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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: diff --git a/config/locales/es_MX.yml b/config/locales/es_MX.yml index 68254c69..a0b6d105 100644 --- a/config/locales/es_MX.yml +++ b/config/locales/es_MX.yml @@ -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: diff --git a/config/locales/fa_IR.yml b/config/locales/fa_IR.yml index e0240819..bd1d21c7 100644 --- a/config/locales/fa_IR.yml +++ b/config/locales/fa_IR.yml @@ -283,7 +283,7 @@ fa_IR: password_different_notice: تاییدیه رمز عبور با رمز ارائه شده مطابقت ندارد. provider: google: گوگل - microsoft_office365: افیس 365 + office365: افیس 365 twitter: توییتر recaptcha: errors: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 0a67e652..251015ae 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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 diff --git a/config/locales/hi_IN.yml b/config/locales/hi_IN.yml index 3ff7299f..aebe071f 100644 --- a/config/locales/hi_IN.yml +++ b/config/locales/hi_IN.yml @@ -155,7 +155,7 @@ hi_IN: password_different_notice: पासवर्ड की पुष्टि मेल नहीं खाती। provider: google: गूगल - microsoft_office365: ऑफिस 365 + office365: ऑफिस 365 twitter: ट्विटर recording: email: ईमेल रिकॉर्डिंग diff --git a/config/locales/hu_HU.yml b/config/locales/hu_HU.yml index 28288ca6..83891157 100644 --- a/config/locales/hu_HU.yml +++ b/config/locales/hu_HU.yml @@ -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: diff --git a/config/locales/it.yml b/config/locales/it.yml index 92a9519a..0d6953cf 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -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: diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 505327b7..d8c1e970 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -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 diff --git a/config/locales/pt_BR.yml b/config/locales/pt_BR.yml index 695c102f..e5e0a32d 100644 --- a/config/locales/pt_BR.yml +++ b/config/locales/pt_BR.yml @@ -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 diff --git a/config/locales/ru_RU.yml b/config/locales/ru_RU.yml index 4c652616..5d8e977e 100644 --- a/config/locales/ru_RU.yml +++ b/config/locales/ru_RU.yml @@ -131,7 +131,7 @@ ru_RU: password_different_notice: Подтверждение пароля не совпадает. provider: google: Google - microsoft_office365: Office 365 + office365: Office 365 twitter: Twitter recording: email: Отправить ссылку на запись diff --git a/config/locales/vi_VN.yml b/config/locales/vi_VN.yml index 5762bc20..1efce94f 100644 --- a/config/locales/vi_VN.yml +++ b/config/locales/vi_VN.yml @@ -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: diff --git a/config/locales/zh_CN.yml b/config/locales/zh_CN.yml index a26fb655..4bf233e9 100644 --- a/config/locales/zh_CN.yml +++ b/config/locales/zh_CN.yml @@ -283,7 +283,7 @@ zh_CN: password_different_notice: 两次新密码不一致。 provider: google: Google - microsoft_office365: Office 365 + office365: Office 365 twitter: Twitter recaptcha: errors: diff --git a/sample.env b/sample.env index 74ba1d00..57b6ba2a 100644 --- a/sample.env +++ b/sample.env @@ -47,6 +47,7 @@ TWITTER_SECRET= # OFFICE365_KEY= OFFICE365_SECRET= +OFFICE365_HD= # LDAP Login Provider (optional) #