Sha256: 27808a0fbe26b424dffb2c255e1a1435744868ffdb1a5e5842564cdaa80eb900

Contents?: true

Size: 1.29 KB

Versions: 12

Compression:

Stored size: 1.29 KB

Contents

require 'openid_connect'

module ForestLiana
  class OidcClientManager
    def self.get_client_for_callback_url(callback_url)
      begin
        client_data = Rails.cache.read(callback_url) || nil
        if client_data.nil?
          configuration = ForestLiana::OidcConfigurationRetriever.retrieve()

          if ForestLiana.forest_client_id.nil?
            client_credentials = ForestLiana::OidcDynamicClientRegistrator.register({
              token_endpoint_auth_method: 'none',
              redirect_uris: [callback_url],
              registration_endpoint: configuration['registration_endpoint']
            })
          else
            client_credentials = { 'client_id' => ForestLiana.forest_client_id }
          end

          client_data = { :client_id => client_credentials['client_id'], :issuer => configuration['issuer'] }
          Rails.cache.write(callback_url, client_data)
        end

        OpenIDConnect::Client.new(
          identifier: client_data[:client_id],
          redirect_uri: callback_url,
          host: "#{client_data[:issuer].sub(/^https?\:\/\/(www.)?/,'')}",
          authorization_endpoint: '/oidc/auth',
          token_endpoint: '/oidc/token',
        )
      rescue => error
        Rails.cache.delete(callback_url)
        raise error
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
forest_liana-6.3.0 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.2.3 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.2.2 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.2.1 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.2.0 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.1.1 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.1.0 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.0.5 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.0.4 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.0.3 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.0.2 app/services/forest_liana/oidc_client_manager.rb
forest_liana-6.0.1 app/services/forest_liana/oidc_client_manager.rb