Class: Bidi2pdf::Bidi::AuthInterceptor

Inherits:
Object
  • Object
show all
Includes:
Interceptor
Defined in:
lib/bidi2pdf/bidi/auth_interceptor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Interceptor

#client, #handle_event, included, #interceptor_id, #register_with_client, #unregister_with_client, #validate_phases!

Constructor Details

#initialize(username:, password:, url_patterns:, context:) ⇒ AuthInterceptor

Returns a new instance of AuthInterceptor.



18
19
20
21
22
23
24
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 18

def initialize(username:, password:, url_patterns:, context:)
  @url_patterns = url_patterns
  @context = context
  @username = username
  @password = password
  @network_ids = []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



16
17
18
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 16

def context
  @context
end

#headersObject (readonly)

Returns the value of attribute headers.



16
17
18
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 16

def headers
  @headers
end

#network_idsObject (readonly)

Returns the value of attribute network_ids.



16
17
18
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 16

def network_ids
  @network_ids
end

#passwordObject (readonly)

Returns the value of attribute password.



16
17
18
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 16

def password
  @password
end

#url_patternsObject (readonly)

Returns the value of attribute url_patterns.



16
17
18
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 16

def url_patterns
  @url_patterns
end

#usernameObject (readonly)

Returns the value of attribute username.



16
17
18
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 16

def username
  @username
end

Class Method Details

.eventsObject



13
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 13

def events = ["network.authRequired"]

.phasesObject



11
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 11

def phases = [Bidi2pdf::Bidi::Commands::AddIntercept::AUTH_REQUIRED]

Instance Method Details

#process_interception(_event_response, navigation_id, network_id, url) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bidi2pdf/bidi/auth_interceptor.rb', line 26

def process_interception(_event_response, navigation_id, network_id, url)
  return if handled_bad_credentials(navigation_id, network_id, url)

  network_ids << network_id

  cmd = Bidi2pdf::Bidi::Commands::ProvideCredentials.new request: network_id, username: username, password: password

  client.send_cmd(cmd)
rescue StandardError => e
  Bidi2pdf.logger.error "Error handling auth event: #{e.message}"
  Bidi2pdf.logger.error e.backtrace.join("\n")
  raise e
end