Skip to content

Commit

Permalink
Merge pull request #5 from lion-packages/support
Browse files Browse the repository at this point in the history
Library documentation and updated dependencies
  • Loading branch information
Sleon4 authored Feb 29, 2024
2 parents 2db9853 + 51ef70b commit 829e4e0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 29 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</p>

## Install

```bash
composer require lion/authentication
```
Expand Down
2 changes: 1 addition & 1 deletion api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

header('Content-Type: application/json');

use LionAuthentication\Auth2FA;
use Lion\Authentication\Auth2FA;

$content = json_decode(file_get_contents("php://input"), true);
$request = $content === null ? ((object) [...$_POST, ...$_GET]) : ((object) $content);
Expand Down
40 changes: 20 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once('./vendor/autoload.php');

use LionAuthentication\Auth2FA;
use Lion\Authentication\Auth2FA;

header('Content-Type: application/json');

Expand Down
41 changes: 38 additions & 3 deletions src/LionAuthentication/Auth2FA.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,49 @@

use PragmaRX\Google2FAQRCode\Google2FA;

/**
* Provides functionality for two-factor authentication (2FA) using Google
* Authenticator
*
* @package Lion\Authentication
*/
class Auth2FA
{
/**
* [Google2FA class object]
*
* @var Google2FA $google2FA
*/
private Google2FA $google2FA;

/**
* Class constructor
*/
public function __construct()
{
$this->google2FA = new Google2FA();
}

/**
* Generates a QR code for two-factor authentication (2FA)
*
* @param string $companyName [The name of the company]
* @param string $companyEmail [The company email]
* @param int $size [The desired size for the QR code]
* @param string $encoding [Text encoding]
* @param int $length [The length of the secret key]
* @param string $prefix [The optional prefix for the secret key]
*
* @return object
*/
public function qr(
string $companyName,
string $companyEmail,
int $size = 200,
string $encoding = 'utf-8',
int $length = 16,
string $prefix = '',
): object
{
string $prefix = ''
): object {
$secretKey = $this->google2FA->generateSecretKey($length, $prefix);

$img = base64_encode(
Expand All @@ -41,6 +66,16 @@ public function qr(
];
}

/**
* Verifies the authenticity of a given secret code, relative to a given
* secret key
*
* @param string $secretKey [The secret key used to generate the QR code]
* @param string $secretCode [The secret code entered by the user for
* authentication]
*
* @return object
*/
public function verify(string $secretKey, string $secretCode): object
{
$validation = (bool) $this->google2FA->verifyKey($secretKey, $secretCode);
Expand Down
6 changes: 3 additions & 3 deletions tests/Auth2FATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class Auth2FATest extends Test
protected function setUp(): void
{
$this->auth2FA = new Auth2FA();

$this->initReflection($this->auth2FA);
}

public function testConstruct(): void
{
$this->initReflection($this->auth2FA);

$this->assertInstanceOf(Google2FA::class, $this->getPrivateProperty(Constanst::PROPIERTY));
$this->assertInstanceOf(Google2FA::class, $this->getPrivateProperty('google2FA'));
}

public function testQr(): void
Expand Down
1 change: 0 additions & 1 deletion tests/Constanst.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class Constanst
{
const PROPIERTY = 'google2FA';
const STATUS = 'status';
const MESSAGE = 'message';
const DATA = 'data';
Expand Down

0 comments on commit 829e4e0

Please sign in to comment.