<?php declare(strict_types=1);
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use Oilastudio\Oneaccount\EngineInterface;
use Oilastudio\Oneaccount\Oneaccount;
class OneaccountController extends Controller
public function oneaccountauth(Request $request)
// provide an implementation of EngineInterface for example redis:
$oneaccount = new Oneaccount(new RedisEngine());
// for development purposes you can use file engine implementation
// (creates files in your file system, make sure to delete them):
// $oneaccount = new Oneaccount(new FileEngine());
$user = $oneaccount->auth();
// NOTE: never return code 200 if a user is not authenticated
return new JsonResponse(['success' => false], 401);
// since One account doesn't differentiate between sign up and sign in,
// you can use userId to check if the user signed up c on your website or not.
// the same way you can access any other data you requested from the user:
// $userId = $user['userId'];
$firstName = $user['firstName'];
// the object contains all fields (camelCased) that are defined in the app (Requested data)
// any data returned here would be sent to oneaccount-authenticated event on front-end e.g.:
return new JsonResponse(['firstName' => $firstName]);
// For production deployment it is recommended to implement the EngineInterface
// Any database or caching system can be used, in this tutorial we will
// demonstrate implementatioon of EngineInterface using redis.
final class RedisEngine implements EngineInterface
public function set(string $key, array $value): bool
Redis::set($key, json_encode($value), 'EX', 3 * 60);
public function get(string $key): array
$data = json_decode(Redis::get($key), true);