jonnybarnes.uk/app/Services/TokenService.php

30 lines
648 B
PHP
Raw Permalink Normal View History

2016-05-19 15:01:28 +01:00
<?php
declare(strict_types=1);
2016-05-19 15:01:28 +01:00
namespace App\Services;
use App\Jobs\AddClientToDatabase;
use App\Models\MicropubToken;
2016-05-19 15:01:28 +01:00
class TokenService
{
/**
* Generate a new bearer token.
2016-05-19 15:01:28 +01:00
*/
public function getNewToken(array $data): string
{
$token = rtrim(strtr(base64_encode(random_bytes(32)), '+/', '-_'), '=');
MicropubToken::create([
'token_hash' => hash('sha256', $token),
'client_id' => $data['client_id'],
'me' => $data['me'],
'scope' => $data['scope'],
]);
dispatch(new AddClientToDatabase($data['client_id']));
2016-05-19 15:01:28 +01:00
return $token;
2016-05-19 15:01:28 +01:00
}
}