GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#579)
by Jesus
07:30
created

SessionsHelper.retrieve_customer_info()   A

Complexity

Conditions 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
c 0
b 0
f 0
dl 0
loc 18
rs 9.5
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 SessionsHelper
20
  # Logs a user into GreenLight.
21
  def login(user)
22
    session[:user_id] = user.id
23
24
    # If there are not terms, or the user has accepted them, check for email verification
25
    if !Rails.configuration.terms || user.accepted_terms
26
      check_email_verified(user)
27
    else
28
      redirect_to terms_path
29
    end
30
  end
31
32
  # If email verification is disabled, or the user has verified, go to their room
33
  def check_email_verified(user)
34
    # Admin users should be redirected to the admin page
35
    if user.has_role? :super_admin
36
      redirect_to admins_path
37
    elsif user.activated?
38
      # Dont redirect to any of these urls
39
      dont_redirect_to = [root_url, signin_url, signup_url, unauthorized_url, internal_error_url, not_found_url]
40
      url = if cookies[:return_to] && !dont_redirect_to.include?(cookies[:return_to])
41
        cookies[:return_to]
42
      else
43
        user.main_room
44
      end
45
46
      # Delete the cookie if it exists
47
      cookies.delete :return_to if cookies[:return_to]
48
49
      redirect_to url
50
    else
51
      redirect_to resend_path
52
    end
53
  end
54
55
  # Logs current user out of GreenLight.
56
  def logout
57
    session.delete(:user_id) if current_user
58
  end
59
60
  # Retrieves the current user.
61
  def current_user
62
    @current_user ||= User.find_by(id: session[:user_id])
63
  end
64
65
  def generate_checksum(user_domain, redirect_url, secret)
66
    string = user_domain + redirect_url + secret
67
    OpenSSL::Digest.digest('sha1', string).unpack1("H*")
68
  end
69
70
  def omniauth_options(env)
71
    provider = env['omniauth.strategy'].options[:name]
72
73
    if Rails.configuration.loadbalanced_configuration
74
      user_domain = parse_user_domain(env["SERVER_NAME"])
75
76
      env['omniauth.strategy'].options[:default_callback_url] = Rails.configuration.gl_callback_url
77
78
      customer_info = retrieve_customer_info(user_domain)
79
80
      raise 'Customer not recognized' unless customer_info
81
82
      if customer_info[:saml]
83
        env['omniauth.strategy'].options[:issuer] = customer_info[:saml][:issuer]
84
        env['omniauth.strategy'].options[:idp_sso_target_url] = customer_info[:saml][:idp_sso_target_url]
85
        env['omniauth.strategy'].options[:idp_cert_fingerprint] = customer_info[:saml][:idp_cert_fingerprint]
86
      elsif customer_info[:google]
87
        env['omniauth.strategy'].options[:hd] = customer_info[:google][:hd] unless
88
          customer_info[:google][:hd].empty? || customer_info[:google][:hd] == 'gmail.com'
89
      elsif customer_info[:office365]
90
        env['omniauth.strategy'].options[:allowed_domains] = customer_info[:office365][:hd] unless
91
        customer_info[:office365][:hd].empty?
92
      end
93
    end
94
95
    if provider == 'google' && !Rails.configuration.loadbalanced_configuration
96
      hd_opts = ENV['GOOGLE_OAUTH2_HD'].split(',')
97
      env['omniauth.strategy'].options[:hd] =
98
        if hd_opts.empty?
99
          nil
100
        elsif hd_opts.length == 1
101
          hd_opts[0]
102
        else
103
          hd_opts
104
        end
105
    end
106
  end
107
108
  def retrieve_customer_info(provider)
109
    provider_info = retrieve_provider_info(provider, 'api2', 'getUserGreenlightCredentials')
110
111
    customer_info = {}
112
    if provider_info['provider'] == 'saml'
113
      customer_info[:saml] = {
114
        issuer: provider_info['SAML_ISSUER'],
115
        idp_sso_target_url: provider_info['SAML_IDP_URL'],
116
        idp_cert_fingerprint: provider_info['SAML_IDP_CERT_FINGERPRINT'],
117
      }
118
    elsif provider_info['provider'] == 'google'
119
      customer_info = { google: { hd: provider_info['GOOGLE_HD'] } }
120
    elsif provider_info['provider'] == 'office365'
121
      customer_info = { office365: { hd: provider_info['OFFICE_365_HD'] } }
122
    end
123
124
    customer_info
125
  end
126
end
127