Sha256: d0dff4dbe69ac42cbc09716d370792122b3811d0a39039191dfb9ba761d87510

Contents?: true

Size: 1.58 KB

Versions: 27

Compression:

Stored size: 1.58 KB

Contents

module ForestLiana
  class Authentication
    def start_authentication(state)
      client = ForestLiana::OidcClientManager.get_client()

      authorization_url = client.authorization_uri({
        scope: 'openid email profile',
        state: state.to_s,
      })

      { 'authorization_url' => authorization_url }
    end

    def verify_code_and_generate_token(params)
      client = ForestLiana::OidcClientManager.get_client()

      rendering_id = parse_state(params['state'])
      client.authorization_code = params['code']

      if Rails.env.development? || Rails.env.test?
        OpenIDConnect.http_config do |config|
          config.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
        end
      end
      access_token_instance = client.access_token! 'none'

      user = ForestLiana::AuthorizationGetter.authenticate(
        rendering_id,
        { :forest_token => access_token_instance.instance_variable_get(:@access_token) },
      )

      return ForestLiana::Token.create_token(user, rendering_id)
    end

    private
    def parse_state(state)
      unless state
        raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_MISSING]
      end

      rendering_id = nil

      begin
        parsed_state = JSON.parse(state.gsub("'",'"').gsub('=>',':'))
        rendering_id = parsed_state["renderingId"].to_s
      rescue
        raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_FORMAT]
      end

      if rendering_id.nil?
        raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_RENDERING_ID]
      end

      return rendering_id
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
forest_liana-7.8.2 app/services/forest_liana/authentication.rb
forest_liana-8.0.15 app/services/forest_liana/authentication.rb
forest_liana-8.0.14 app/services/forest_liana/authentication.rb
forest_liana-8.0.13 app/services/forest_liana/authentication.rb
forest_liana-8.0.12 app/services/forest_liana/authentication.rb
forest_liana-8.0.11 app/services/forest_liana/authentication.rb
forest_liana-8.0.10 app/services/forest_liana/authentication.rb
forest_liana-8.0.9 app/services/forest_liana/authentication.rb
forest_liana-8.0.8 app/services/forest_liana/authentication.rb
forest_liana-8.0.7 app/services/forest_liana/authentication.rb
forest_liana-8.0.6 app/services/forest_liana/authentication.rb
forest_liana-8.0.5 app/services/forest_liana/authentication.rb
forest_liana-8.0.4 app/services/forest_liana/authentication.rb
forest_liana-8.0.3 app/services/forest_liana/authentication.rb
forest_liana-8.0.2 app/services/forest_liana/authentication.rb
forest_liana-8.0.1 app/services/forest_liana/authentication.rb
forest_liana-8.0.0 app/services/forest_liana/authentication.rb
forest_liana-7.8.1 app/services/forest_liana/authentication.rb
forest_liana-8.0.0.beta.4 app/services/forest_liana/authentication.rb
forest_liana-8.0.0.beta.3 app/services/forest_liana/authentication.rb