Technical Implementation

Unify Laravel Auth

To use this package, you must first obtain access to the Unify Composer repository. You must also have received a Unify Key.

Installation

  1. Add the Unify composer repository to your project's composer.json file.
{
	"repositories": [
        {
            "type": "composer",
            "url": "https://composer.getunify.com"
        }
    ]
}
  1. Install the package by running the following command in your project directory.
composer require getunify/laravel-auth

During installation, you might be prompted by Composer to enter your repository credentials.

  1. After installation, open config/auth.php and change your default guard to unify.
'defaults' > [
    'guard' => 'unify',
    'passwords' => 'users',
],
  1. Add your Unify Key to your .env file.
UNIFY_KEY=[REDACTED]

Usage

If a user is not logged in and visits a protected page, they are redirected to Unify and asked to log in first. After the user logs in, they automatically return to the protected page they intended to visit.

Require user authentication to view a page

Use the auth middleware to protect a route with authentication.

// In your routes file, for example: routes/web.php
Route::get('/pages/example-page')->middleware('auth');

// In a controller, for example: app/Http/Controllers/FooController.php
class FooController extends Controller
{
    public function __construct() 
    {
        $this->middleware('auth');
    }
}

Only allow a specific access level to view a page

Pages that require a certain access level can be protected with the unify.level middleware.

// Only allow users with access level 1
Route::get('/pages/example-page')->middleware('unify.level:1');

// Only allow users with access level 0 or 2, but not 1
Route::get('/pages/example-page')->middleware('unify.level:0,2');

See the Laravel documentation to learn more about middleware:

Check if the user is logged in

Use Laravel's authentication helpers to determine if the user is logged in.

if (Auth::check()) {
    // Run code when user is authenticated
}

if (Auth::guest()) {
    // Run code when user is not logged in
}

Reading user information

Use Laravel's authentication helpers to retrieve user information.

The returned value from Auth::user() is an instance of \Unify\LaravelAuth\Session\Profile. If there is no user logged in, the returned value is null.

You can type-hint \Unify\LaravelAuth\Session\Profile on controller methods to automatically get the user object injected by Laravel.

From the user object you can read information.

use Illuminate\Support\Facades\Auth;

$user = Auth::user();

Available properties

$user->id; // "be9f339215128334459eed3a7c6b40cf"
$user->initials; // "J.E."
$user->name; // "Jane Doe"
$user->firstName; // "Jane"
$user->lastName; // "Doe"
$user->formalName; // "J.E. Doe"
$user->indexableName; // "Doe, Jane"
$user->email; // "jane.e.doe@example.com"
$user->timezone; // "Europe/Amsterdam"
$user->locale; // "nl"
$user->onekeyId; // "WNLR00000000"
$user->registrations; // ["foo_number" => "TEST001UNIFY", "bar_number" => "TEST002UNIFY"]

$user->address->organization; // "Acme Inc."
$user->address->street; // "Example St."
$user->address->number; // "42"
$user->address->letter; // "a"
$user->address->postalCode; // "1010AB"
$user->address->city; // "Amsterdam"
$user->address->country; // "NL"

Available methods

$user->hasAccessLevel0(); // true | false
$user->hasAccessLevel1(); // true | false
$user->hasAccessLevel2(); // true | false

$user->isDeveloper(); // true | false
$user->isEmployee(); // true | false
$user->isAdministrator(); // true | false

Logging out

To end the user's session, have them visit the logout route of your application.

EMEA

Unify Europe

Pieter Smit Sales

Ankerweg 2

1041 AT

Amsterdam

+31 88 44 70 000

Mon-Fri 9am-6pm CET

AMER

Unify LLC

Unify Europe Sales

14425 Falcon Head Blvd.

Building E - Suite 100

Austin, TX 78738

+17372191977

Mon-Fri 9am-6pm CET

APAC

Unify LTD

Unify Europe Sales

1-2-20 Kaigan

3/F Shiodome Building

Tokyo, 105-0022

sales@getunify.com

Mon-Fri 9am-6pm CET

Unify is not affiliated with IQVIA or IQVIA's team, nor is it endorsed by or related to IQVIA. Unify is not affiliated with Veeva Systems or Veeva Systems's team, nor is it endorsed by or related to Veeva Systems. Unify is a division of SMIT. Digitaal vakmanschap BV. Crafted in Amsterdam.

© Unify LLC. All rights reserved.