Users

Introduction

Users in the context of the Authy Authenticator are records of users that have enabled two-factor authentication.

Checking Authy Status

To check if a user has a valid Authy user ID attached and is therefore enrolled in two-factor authentication use the get_authy_id hook.

if ($id = auth()->user()->getAuthyId()) {
    echo "Authy User ID: {$id}";
}
{% if user().authy_id %}
    Authy User ID: {{ user().authy_id }}
{% endif %}

Retrieving the Authy User

You can also fetch the Authy user instance if needed similarly with the get_authy hook.

if ($authyUser = auth()->user()->getAuthy()) { 
    echo "Authy Country: {$authyUser->getCountry()}";
}
Authy Country: {{ user().authy.country }}

Creating Authy Users

User Repository

You can create an authy user and therefore enable two-factor authentication by using the UserRepositoryInterface.

Use the create method to create a new Authy instance and supply the user instance, cell phone, and country (as an ISO2 code).

$authyUsers = app(\Anomaly\AuthyAuthenticatorExtension\User\Contract\UserRepositoryInterface::class);

$authyUser = $authyUsers->create(
    auth()->user(), // User instance
    3195872109,     // Cell phone
    'US'            // Country
);

Register Form

You can also display a form for a user to fill out this information on their own and enable two-factor authentication for their account.

The following code will work as a create/update form for Authy enrollment.

<p>
    This requires the <a href="https://authy.com/" target="_blank">Authy</a> app.
</p>

{% set form = form('authy_register')
    .entry(user().authy.id)
    .user(user())   
    .redirect(url_previous())
    .get() %}

{{ form.open|raw }}
{{ form.fields|raw }}
{{ form.actions|raw }}
{{ form.close|raw }}

User Route

You can use the included

Deleting Authy Users

User Repository

You can programmatically delete an authy user and therefore disable two-factor authentication by using the UserRepositoryInterface as well.

Use the delete method to delete the Authy user instance.

$authyUsers = app(\Anomaly\AuthyAuthenticatorExtension\User\Contract\UserRepositoryInterface::class);

$authyUsers->delete(user()->getAuthy());

User Route

You can also display a link for the user to use on their own to disable their two-factor authentication:

<a href="{{ user().route('authy_disable') }}">Disable Two-Factor Authentication</a>