Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #61 from kachar/qr_code_request
Browse files Browse the repository at this point in the history
Added QR code request to authy api client
  • Loading branch information
luisuribe authored Jan 10, 2019
2 parents 3fa3b36 + c01dedf commit 678cc04
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/Authy/AuthyApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@ public function userStatus($authy_id)
return new AuthyResponse($resp);
}

/**
* Request QR code link.
*
* @param string $authy_id User's id stored in your database
* @param array $opts Array of options, for example: array("qr_size" => 300)
*
* @return AuthyResponse the server response
*/
public function qrCode($authy_id, $opts = [])
{
$authy_id = urlencode($authy_id);
$resp = $this->rest->post("protected/json/users/{$authy_id}/secret", array_merge(
$this->default_options,
['query' => $opts]
));

return new AuthyResponse($resp);
}

/**
* Starts phone verification. (Sends token to user via sms or call).
*
Expand Down Expand Up @@ -275,7 +294,7 @@ public function phoneInfo($phone_number, $country_code)
public function createApprovalRequest($authy_id, $message, $opts = [])
{
$opts['message'] = $message;

$authy_id = urlencode($authy_id);
$resp = $this->rest->post("onetouch/json/users/{$authy_id}/approval_requests", array_merge(
$this->default_options,
Expand Down
22 changes: 22 additions & 0 deletions tests/Authy/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,28 @@ public function testPhonceCallWithValidUser()
$this->assertRegExp('/Call started/i', $call->message());
}

public function testQrCodeWithInvalidUser()
{
$mock_client = $this->mockClient([[404, '{"errors": {"message": "User not found."}}']]);
$call = $mock_client->qrCode(0, []);

$this->assertEquals(false, $call->ok());
$this->assertEquals("User not found.", $call->errors()->message);
}

public function testQrCodeWithValidUser()
{
$mock_client = $this->mockClient([
[200, '{ "user": { "id": 2 } }'],
[200, '{ "qr_code": "https://example.com/qr.png" }']
]);
$user = $mock_client->registerUser('[email protected]', '305-456-2345', 1);
$call = $mock_client->qrCode($user->id(), []);

$this->assertEquals(true, $call->ok());
$this->assertNotNull($call->bodyvar('qr_code'));
}

public function testDeleteUserWithInvalidUser()
{
$mock_client = $this->mockClient([[404, '{"errors": {"message": "User not found."}}']]);
Expand Down

0 comments on commit 678cc04

Please sign in to comment.