Class: Vonage::NetworkNumberVerification

Inherits:
Namespace
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/vonage/network_number_verification.rb

Instance Method Summary collapse

Instance Method Details

#generate_oidc_uri(phone_number:, redirect_uri:, state:) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/vonage/network_number_verification.rb', line 80

def generate_oidc_uri(phone_number:, redirect_uri:, state:)
  params = {
    purpose: 'FraudPreventionAndDetection',
    api_scope: 'number-verification-verify-read',
    login_hint: phone_number,
    redirect_uri: redirect_uri,
    state: state
  }

  Vonage::NetworkAuthentication::ClientAuthentication.new(@config).generate_oidc_uri(**params)
end

#verify(phone_number:, auth_data:) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vonage/network_number_verification.rb', line 39

def verify(phone_number:, auth_data:)
  raise ArgumentError.new("`phone_number` must be in E.164 format") unless Phonelib.parse(phone_number).valid?
  raise ArgumentError.new("`phone_number` must be prepended with a `+`") unless phone_number.start_with?('+')
  raise ArgumentError.new("`auth_data` must contain key `:oidc_auth_code`") unless auth_data.has_key?(:oidc_auth_code)
  raise ArgumentError.new("`auth_data[:oidc_auth_code]` must be a String") unless auth_data[:oidc_auth_code].is_a?(String)
  raise ArgumentError.new("`auth_data` must contain key `:redirect_uri`") unless auth_data.has_key?(:redirect_uri)
  raise ArgumentError.new("`auth_data[:redirect_uri]` must be a String") unless auth_data[:redirect_uri].is_a?(String)

  params = {phone_number: phone_number}

  request(
    '/camara/number-verification/v031/verify',
    params: camelcase(params),
    type: Post,
    auth_data: {
      oidc_auth_code: auth_data[:oidc_auth_code],
      redirect_uri: auth_data[:redirect_uri],
      auth_flow: :client_authentication
    }
  )
end