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.5.3 app/services/forest_liana/authentication.rb
forest_liana-9.5.2 app/services/forest_liana/authentication.rb
forest_liana-9.5.1 app/services/forest_liana/authentication.rb
forest_liana-9.5.0 app/services/forest_liana/authentication.rb
forest_liana-9.4.3 app/services/forest_liana/authentication.rb
forest_liana-9.4.2 app/services/forest_liana/authentication.rb
forest_liana-9.4.1 app/services/forest_liana/authentication.rb
forest_liana-9.4.0 app/services/forest_liana/authentication.rb
forest_liana-8.3.3 app/services/forest_liana/authentication.rb
forest_liana-9.3.16 app/services/forest_liana/authentication.rb
forest_liana-9.3.15 app/services/forest_liana/authentication.rb
forest_liana-9.3.14 app/services/forest_liana/authentication.rb
forest_liana-9.3.13 app/services/forest_liana/authentication.rb
forest_liana-9.3.12 app/services/forest_liana/authentication.rb
forest_liana-9.3.11 app/services/forest_liana/authentication.rb
forest_liana-9.3.10 app/services/forest_liana/authentication.rb
forest_liana-9.3.9 app/services/forest_liana/authentication.rb
forest_liana-9.3.8 app/services/forest_liana/authentication.rb
forest_liana-9.3.7 app/services/forest_liana/authentication.rb
forest_liana-9.3.6 app/services/forest_liana/authentication.rb