<commit_before># frozen_string_literal: true

require 'omniauth/saml/certificate_loader'

module OmniAuth
  module Strategies
    # Monkey-patch for Omniauth Azure AD.
    # @see https://github.com/AzureAD/omniauth-azure-activedirectory/issues/25
    class AzureActiveDirectory
      def raw_authorize_endpoint_url
        hostname = 'login.windows.net'
        if ENV.key?('AZUREAD_ENDPOINT_HOSTNAME')
          hostname = ENV['AZUREAD_ENDPOINT_HOSTNAME']
        end
        'https://' + hostname + '/common/oauth2/authorize'
      end

      def authorize_endpoint_url
        uri = URI(raw_authorize_endpoint_url)
        uri.query = URI.encode_www_form(client_id: client_id,
                                        redirect_uri: callback_url,
                                        response_mode: response_mode,
                                        response_type: response_type,
                                        nonce: new_nonce)
        uri.to_s
      end

      def verify_options
        { verify_expiration: true,
          verify_not_before: true,
          verify_iat: true,
          verify_aud: true,
          'aud' => client_id }
      end
    end
  end
end

# Initialise Omniauth config.
Rails.application.config.middleware.use OmniAuth::Builder do
  # Google OAuth2 authentication.
  if ENV.key?('GOOGLE_CLIENT_ID') && ENV.key?('GOOGLE_CLIENT_SECRET')
    provider :google_oauth2,
             ENV['GOOGLE_CLIENT_ID'],
             ENV['GOOGLE_CLIENT_SECRET'],
             skip_jwt: true
  end

  # Facebook authentication.
  if ENV.key?('FACEBOOK_APP_ID') && ENV.key?('FACEBOOK_APP_SECRET')
    provider :facebook,
             ENV['FACEBOOK_APP_ID'],
             ENV['FACEBOOK_APP_SECRET']
  end

  # SAML authentication.<commit_msg>[AM-64] Eliminate azuread monkeypatch<commit_after># frozen_string_literal: true

require 'omniauth/saml/certificate_loader'

# Initialise Omniauth config.
Rails.application.config.middleware.use OmniAuth::Builder do
  # Google OAuth2 authentication.
  if ENV.key?('GOOGLE_CLIENT_ID') && ENV.key?('GOOGLE_CLIENT_SECRET')
    provider :google_oauth2,
             ENV['GOOGLE_CLIENT_ID'],
             ENV['GOOGLE_CLIENT_SECRET'],
             skip_jwt: true
  end

  # Facebook authentication.
  if ENV.key?('FACEBOOK_APP_ID') && ENV.key?('FACEBOOK_APP_SECRET')
    provider :facebook,
             ENV['FACEBOOK_APP_ID'],
             ENV['FACEBOOK_APP_SECRET']
  end

  # SAML authentication.
{'fraction_non_alphanumeric': 0.09272061813745425, 'fraction_numerical': 0.0036600244001626678, 'mean_word_length': 2.407202216066482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6791561', 'n_tokens_mistral': 798, 'n_tokens_neox': 769, 'n_words': 133}