My current workflow is:
1) After user registered, automatically create a Personal Access Token (PAT) to access the API
2) However once the token is created, how are we able to display the PAT again.
// Creating a token with scopes...
$token = $user->createToken('Pricing Token', ['get-pricing])->accessToken;
Essentially it would be good for the user, once they have logged in to my secured site to download the Token at any time to use on their own site. Essentially I'm using the PAT to identify the user so don't need the full OAUTH workflow.
Reading through the source code, I'm able to regenerate the Access token, but how are we able to retrieve the original Token generated in Step 2.
+1
+1
I created this trait to grab the latest valid token for a user, with the default personal access client.
<?php
namespace App\Models\Traits;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Token;
use Laravel\Passport\TokenRepository;
trait AccessToken
{
/**
* Get personal access token for user.
*
* @return \Laravel\Passport\Token|null
*/
public function getToken(): ?Token
{
return app(TokenRepository::class)->findValidToken(
$this,
app(ClientRepository::class)->personalAccessClient()
);
}
}
Why not acces it from database?
Hey there. There's a token and tokens method on the HasApiTokens trait. Is this what you need? Please note that these aren't filtered on revoked etc.
@driesvints it seems those two methods don't include personal access tokens?
Is it possible for me to retrieve the ACCESS TOKEN string from a Laravel\Passport\Token object?
Is it possible for me to retrieve the ACCESS TOKEN string from a Laravel\Passport\Token object?
I would like to know this too! In passport it is pretty easy to create tokens and clients, but not so easy (not documented well enough) to get tokens after they are created.
Why not acces it from database?
Do you have code for this task ?
Most helpful comment
+1