Sha256: 5cddf99be6d70472564b02f5c625bd56cc800b7cf53c8a5ce919924269140e70

Contents?: true

Size: 1.56 KB

Versions: 47

Compression:

Stored size: 1.56 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

      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

47 entries across 47 versions & 1 rubygems

Version Path
forest_liana-9.3.3 app/services/forest_liana/authentication.rb
forest_liana-9.3.2 app/services/forest_liana/authentication.rb
forest_liana-8.3.1 app/services/forest_liana/authentication.rb
forest_liana-9.3.1 app/services/forest_liana/authentication.rb
forest_liana-9.3.0 app/services/forest_liana/authentication.rb
forest_liana-8.3.0 app/services/forest_liana/authentication.rb
forest_liana-9.2.3 app/services/forest_liana/authentication.rb
forest_liana-9.2.2 app/services/forest_liana/authentication.rb
forest_liana-9.2.1 app/services/forest_liana/authentication.rb
forest_liana-9.2.0 app/services/forest_liana/authentication.rb
forest_liana-9.1.10 app/services/forest_liana/authentication.rb
forest_liana-9.1.9 app/services/forest_liana/authentication.rb
forest_liana-9.1.8 app/services/forest_liana/authentication.rb
forest_liana-9.1.7 app/services/forest_liana/authentication.rb
forest_liana-9.1.6 app/services/forest_liana/authentication.rb
forest_liana-9.1.5 app/services/forest_liana/authentication.rb
forest_liana-9.1.4 app/services/forest_liana/authentication.rb
forest_liana-9.1.3 app/services/forest_liana/authentication.rb
forest_liana-9.1.2 app/services/forest_liana/authentication.rb
forest_liana-9.1.1 app/services/forest_liana/authentication.rb