LaravelPackages.net
Acme Inc.
Toggle sidebar
ollyxar/laravel-auth

Laravel auth helper

931
4
1.1.2
About ollyxar/laravel-auth

ollyxar/laravel-auth is a Laravel package for laravel auth helper. It currently has 4 GitHub stars and 931 downloads on Packagist (latest version 1.1.2). Install it with composer require ollyxar/laravel-auth. Discover more Laravel packages by ollyxar or browse all Laravel packages to compare alternatives.

Last updated

Laravel auth helper

Version Downloads License

Get user's id from session identified by cookie

Why auth helper?

Auth helper designed for external PHP application authentication. It helps developers to get user_id from their session without any auth-token or any authorize process.

How it's work?

Suppose you have some PHP server application that need to know who is making request. It can be some artisan command requiring authorization or WebSocket server in another port that is listening connections.

In the browser user go to some address (obviously it must have the same domain). Thus browser sends current headers to your application. And then you can use Cookie from the headers to define client.

License

Example

Here is a simple example how to determine user_id

// if the sessions are in files by default
use Ollyxar\LaravelAuth\FileAuth;

// or if the sessions in the Redis
// use Ollyxar\LaravelAuth\RedisAuth;

// The same code for Redis except you have to call RedisAuth instead
if ($userId = FileAuth::getUserIdByHeaders($headers)) {
    // we got it!
}

You have to provide correct $headers array that must content Cookie item. Otherwise $user_id will return false

The headers should be like:

$headers = [
    'Cookie' => 'someotherkey=someothervalue;laravel_session=somerandomstring'
];

Please notice that auth helper use the same native methods / functions to find session by cookie.

Comments