farhatahmad /
greenlight
| 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 | case env['omniauth.strategy'].options[:name] |
||
| 24 | when "bn_launcher" |
||
| 25 | protocol = Rails.env.production? ? "https" : env["rack.url_scheme"] |
||
| 26 | |||
| 27 | customer_redirect_url = "#{protocol}://#{env['SERVER_NAME']}:#{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 | when "google" |
||
| 37 | set_hd(env, ENV['GOOGLE_OAUTH2_HD']) |
||
| 38 | when "office365" |
||
| 39 | set_hd(env, ENV['OFFICE365_HD']) |
||
| 40 | when "openid_connect" |
||
| 41 | set_hd(env, ENV['OPENID_CONNECT_HD']) |
||
| 42 | end |
||
| 43 | end |
||
| 44 | |||
| 45 | # Limits the domain that can be used with the provider |
||
| 46 | def set_hd(env, hd) |
||
| 47 | if hd |
||
| 48 | hd_opts = hd.split(',') |
||
| 49 | env['omniauth.strategy'].options[:hd] = if hd_opts.empty? |
||
| 50 | nil |
||
| 51 | elsif hd_opts.length == 1 |
||
| 52 | hd_opts[0] |
||
| 53 | else |
||
| 54 | hd_opts |
||
| 55 | end |
||
| 56 | end |
||
| 57 | end |
||
| 58 | |||
| 59 | # Parses the url for the user domain |
||
| 60 | View Code Duplication | def parse_user_domain(hostname) |
|
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
| 61 | return hostname.split('.').first if Rails.configuration.url_host.empty? |
||
| 62 | Rails.configuration.url_host.split(',').each do |url_host| |
||
| 63 | return hostname.chomp(url_host).chomp('.') if hostname.include?(url_host) |
||
| 64 | end |
||
| 65 | '' |
||
| 66 | end |
||
| 67 | |||
| 68 | # Generates a checksum to use alongside the omniauth request |
||
| 69 | def generate_checksum(user_domain, redirect_url, secret) |
||
| 70 | string = user_domain + redirect_url + secret |
||
| 71 | OpenSSL::Digest.digest('sha1', string).unpack1("H*") |
||
| 72 | end |
||
| 73 | end |
||
| 74 |