1
|
|
|
# frozen_string_literal: true |
2
|
|
|
|
3
|
|
|
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. |
4
|
|
|
# |
5
|
|
|
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below). |
6
|
|
|
# |
7
|
|
|
# This program is free software; you can redistribute it and/or modify it under the |
8
|
|
|
# terms of the GNU Lesser General Public License as published by the Free Software |
9
|
|
|
# Foundation; either version 3.0 of the License, or (at your option) any later |
10
|
|
|
# version. |
11
|
|
|
# |
12
|
|
|
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY |
13
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
14
|
|
|
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU Lesser General Public License along |
17
|
|
|
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
module OmniauthOptions |
20
|
|
|
module_function |
21
|
|
|
|
22
|
|
|
def omniauth_options(env) |
23
|
|
|
if env['omniauth.strategy'].options[:name] == "bn_launcher" |
24
|
|
|
protocol = Rails.env.production? ? "https" : env["rack.url_scheme"] |
25
|
|
|
|
26
|
|
|
customer_redirect_url = protocol + "://" + env["SERVER_NAME"] + ":" + |
27
|
|
|
env["SERVER_PORT"] |
28
|
|
|
user_domain = parse_user_domain(env["SERVER_NAME"]) |
29
|
|
|
env['omniauth.strategy'].options[:customer] = user_domain |
30
|
|
|
env['omniauth.strategy'].options[:customer_redirect_url] = customer_redirect_url |
31
|
|
|
env['omniauth.strategy'].options[:default_callback_url] = Rails.configuration.gl_callback_url |
32
|
|
|
|
33
|
|
|
# This is only used in the old launcher and should eventually be removed |
34
|
|
|
env['omniauth.strategy'].options[:checksum] = generate_checksum(user_domain, customer_redirect_url, |
35
|
|
|
Rails.configuration.launcher_secret) |
36
|
|
|
elsif env['omniauth.strategy'].options[:name] == "google" |
37
|
|
|
set_hd(env, ENV['GOOGLE_OAUTH2_HD']) |
38
|
|
|
elsif env['omniauth.strategy'].options[:name] == "office365" |
39
|
|
|
set_hd(env, ENV['OFFICE365_HD']) |
40
|
|
|
end |
41
|
|
|
end |
42
|
|
|
|
43
|
|
|
# Limits the domain that can be used with the provider |
44
|
|
|
def set_hd(env, hd) |
45
|
|
|
if hd |
46
|
|
|
hd_opts = hd.split(',') |
47
|
|
|
env['omniauth.strategy'].options[:hd] = if hd_opts.empty? |
48
|
|
|
nil |
49
|
|
|
elsif hd_opts.length == 1 |
50
|
|
|
hd_opts[0] |
51
|
|
|
else |
52
|
|
|
hd_opts |
53
|
|
|
end |
54
|
|
|
end |
55
|
|
|
end |
56
|
|
|
|
57
|
|
|
# Parses the url for the user domain |
58
|
|
View Code Duplication |
def parse_user_domain(hostname) |
|
|
|
|
59
|
|
|
return hostname.split('.').first if Rails.configuration.url_host.empty? |
60
|
|
|
Rails.configuration.url_host.split(',').each do |url_host| |
61
|
|
|
return hostname.chomp(url_host).chomp('.') if hostname.include?(url_host) |
62
|
|
|
end |
63
|
|
|
'' |
64
|
|
|
end |
65
|
|
|
|
66
|
|
|
# Generates a checksum to use alongside the omniauth request |
67
|
|
|
def generate_checksum(user_domain, redirect_url, secret) |
68
|
|
|
string = user_domain + redirect_url + secret |
69
|
|
|
OpenSSL::Digest.digest('sha1', string).unpack1("H*") |
70
|
|
|
end |
71
|
|
|
end |
72
|
|
|
|