php - How to get id from refresh token in Laravel Passport?
Get the solution ↓↓↓I am writing a controller in which I would like to get the refresh token id but I just cannot figure out how to do it in laravel.
There are no problems with decrypting the access token. I am using standard protocol and receive data using the public key of the passport.
i tried different ways.
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class RefreshTokenController extends Controller
{
public static $public_key;
public static function refresh_token(Request $request)
{
self::$public_key = file_get_contents(storage_path() . DIRECTORY_SEPARATOR . 'oauth-public.key');
$refresh_token = $request->get('refresh_token');
$data = base64_decode($refresh_token);
$public_key = openssl_get_publickey(self::$public_key);
openssl_public_decrypt($data, $decrypted, $public_key);
dd($decrypted);
}
}
I tried also standarddecrypt();
. But it gives an error too.
Example of incoming data.
def50200dc11ab81fdb16530806530f85fe41f7facc934447589b3a0daa202d56f5b4a8265db94b418e09280bcc8a05c88c3817612200d3c28de15c9adfd4a213f7cb136fca6f78099d686fce8d5ddf93f9bb29c1df081d7f7b75394875b5287a7ca5d9ca5eb513ea13a26195aeda41c897832467ec1b0348cdb3e5ed9476e5e7d8712b8628c18ee8ffb525de965faeb3f25b1a8eb4ee904a15341650fe6d3ed901600beda0f80c71b9b607f3e549ba8fbd9eda0e02fc7647ab8b4ea9161f7eb65833bfe46fb7f3e116a207282f947660ead392dc78ad2b9501331b4d28433a421a4193484e113baf8050d3878bd94b6ac860a1a766e79877f1af8d3ab5aee3779bf33c2a7e347552e51bb8b5448585435ef7b79d06853bcd775ce781b8d2e56289dbc8d4a10ec507aecde19bb496e90f88a687ee9bb33755046d50f860f7723d87bd4c079cd4d1242903bdb3ca447ce6ab03f2fd800182d0d8c5a3b7de5402ba2ecb4058d458cbee94da433635877e63120d6418e51eafdfd763191fceef399c16c088e27da9ffbf9
according to oauth_refresh_tokens table. All refresh token IDs are preserved. When calling the refresh token method, according to the refresh token, the corresponding access token matches in the database and is renewed.
I will be grateful for solutions.
Answer
Solution:
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Defuse\Crypto\Crypto;
use Exception;
use Illuminate\Http\Request;
class RefreshTokenController extends Controller
{
public static function refresh_token(Request $request)
{
$refresh_token = $request->get('refresh_token');
$app_key = env('APP_KEY');
$enc_key = base64_decode(substr($app_key, 7));
try {
$crypto = Crypto::decryptWithPassword($refresh_token, $enc_key);
} catch (Exception $exception){
return $exception;
}
return json_decode($crypto, true);
}
}
Laravel Passport encrypts the password using the APP_ located in the ENV file.
Using the libraryDefuse\Crypto\Crypto;
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: target class [commandmakecommand] does not exist.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.