Fixed #291 Added OAuth2 for Office365 (GRN-32) (#293)

* <Added omniauth for office365>

* <Fixed code style>

* Update puma.rb

* <Inserted link to documentation>
This commit is contained in:
John Ma 2018-10-16 12:58:06 -04:00 committed by Jesus Federico
parent 90b965d03f
commit ec250f3ed5
7 changed files with 38 additions and 3 deletions

View File

@ -47,6 +47,7 @@ gem 'bcrypt', '~> 3.1.7'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-google-oauth2'
gem 'omniauth-microsoft-office365', '~> 0.0.7'
gem 'omniauth-ldap'
gem 'omniauth-bn-launcher', '~> 0.1.0'

View File

@ -160,6 +160,9 @@ GEM
omniauth (~> 1.8.1)
pyu-ruby-sasl (~> 0.0.3.3)
rubyntlm (~> 0.6.2)
omniauth-microsoft-office365 (0.0.7)
omniauth
omniauth-oauth2
omniauth-oauth (1.1.0)
oauth
omniauth (~> 1.0)
@ -338,6 +341,7 @@ DEPENDENCIES
omniauth-bn-launcher (~> 0.1.0)
omniauth-google-oauth2
omniauth-ldap
omniauth-microsoft-office365 (~> 0.0.7)
omniauth-twitter
pg (~> 0.18)
puma (~> 3.0)

View File

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

View File

@ -41,6 +41,12 @@
<% end %>
<% end %>
<% if configured_providers.include? :microsoft_office365 %>
<%= link_to omniauth_login_url(:microsoft_office365), class: "btn btn-pill btn-primary btn-block" do %>
<i class="fab fa-windows"></i>&ensp;<%= t("modal.login.with", provider: "Office365") %>
<% end %>
<% end %>
<div class="or-line my-6">
<div>
<span class="text-uppercase">

View File

@ -40,6 +40,12 @@
<% end %>
<% end %>
<% if configured_providers.include? :microsoft_office365 %>
<%= link_to omniauth_login_url(:microsoft_office365), class: "btn btn-pill btn-primary btn-block" do %>
<i class="fab fa-windows"></i>&ensp;<%= t("signup.with", provider: "Office365") %>
<% end %>
<% end %>
<div class="or-line my-3">
<div>
<span class="text-uppercase" style="background-color: #F5F7FB;">

View File

@ -1,11 +1,13 @@
# frozen_string_literal: true
# List of supported Omniauth providers.
Rails.application.config.providers = [:google, :twitter, :ldap]
Rails.application.config.providers = [:google, :twitter, :microsoft_office365, :ldap]
# Set which providers are configured.
Rails.application.config.omniauth_google = ENV['GOOGLE_OAUTH2_ID'].present? && ENV['GOOGLE_OAUTH2_SECRET'].present?
Rails.application.config.omniauth_twitter = ENV['TWITTER_ID'].present? && ENV['TWITTER_SECRET'].present?
Rails.application.config.omniauth_microsoft_office365 = ENV['OFFICE365_KEY'].present? &&
ENV['OFFICE365_SECRET'].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?
@ -35,6 +37,8 @@ Rails.application.config.middleware.use OmniAuth::Builder do
name: 'google',
hd: ENV['GOOGLE_OAUTH2_HD'].blank? ? nil : ENV['GOOGLE_OAUTH2_HD']
provider :microsoft_office365, ENV['OFFICE365_KEY'], ENV['OFFICE365_SECRET']
provider :ldap,
host: ENV['LDAP_SERVER'],
port: ENV['LDAP_PORT'] || '389',

View File

@ -38,6 +38,15 @@ GOOGLE_OAUTH2_HD=
TWITTER_ID=
TWITTER_SECRET=
# Microsoft Office365 Login Provider (optional)
#
# For in-depth steps on setting up a Office 365 Login Provider, see:
#
# http://docs.bigbluebutton.org/install/greenlight-v2.html#office365-oauth2
#
OFFICE365_KEY=
OFFICE365_SECRET=
# LDAP Login Provider (optional)
#
# You can enable LDAP authentication by providing values for the variables below.