Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform API | Client challenge for phone verification requests #170

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ioki/apis/platform_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ class PlatformApi
base_path: [API_BASE_PATH, 'captchas', :id],
path: 'solution',
model_class: Ioki::Model::Platform::Captcha
),
Endpoints::Create.new(
:client_challenge,
base_path: [API_BASE_PATH, 'client_challenges', :id],
path: 'solution',
model_class: Ioki::Model::Platform::ClientChallenge
)
].freeze
end
Expand Down
18 changes: 18 additions & 0 deletions lib/ioki/model/platform/client_challenge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Ioki
module Model
module Platform
class ClientChallenge < Base
attribute :type, on: :read, type: :string
attribute :id, on: :read, type: :string
attribute :created_at, on: :read, type: :date_time
attribute :updated_at, on: :read, type: :date_time
attribute :challenge, on: :read, type: :string

attribute :solution, on: :create, type: :string
attribute :nonce, on: :create, type: :string
end
end
end
end
1 change: 1 addition & 0 deletions lib/ioki/model/platform/phone_verification_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def self.schema_path
attribute :phone_number, on: [:read, :create], type: :string
attribute :locale, on: [:create], type: :string, unvalidated: true
attribute :captcha, type: :object, on: :read, class_name: 'Captcha'
attribute :client_challenge, type: :object, on: :read, class_name: 'ClientChallenge'
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/ioki/platform_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,18 @@
.to eq(Ioki::Model::Platform::Captcha.new)
end
end

describe '#create_client_challenge(id, client_challenge)' do
it 'calls request on the client with expected params' do
expect(platform_client).to receive(:request) do |params|
expect(params[:url].to_s).to eq('platform/client_challenges/0815/solution')
expect(params[:method]).to eq(:post)
[result_with_data, full_response]
end

client_challenge = Ioki::Model::Platform::ClientChallenge.new(solution: 'w3sd', nonce: '1234')
expect(platform_client.create_client_challenge('0815', client_challenge, options))
.to eq(Ioki::Model::Platform::ClientChallenge.new)
end
end
end