Passport: Shorter personal access tkoen

Created on 6 Nov 2017  ·  10Comments  ·  Source: laravel/passport

I generated a personal access token and the length is 1074 whereas the token stored in database is 80. Is there a way to get a shorter token since I will be giving this to the users for api access and this is too long or is it possible to use the token generated and stored in the database?

Most helpful comment

I hope you find this helpful.
If you want to just show the first n characters of generated personal access token, try to change this.accessToken = accessToken to this.accessToken = accessToken.substring(1, n); in showAccessToken function of PersonalAccessTokens.vue

All 10 comments

You can change default length in vendor/laravel/passport/src/Console/KeysCommand.php.

$keys = $rsa->createKey(4096);

@RezaGhanbari I did try that but still the length is 1071. I did dump-autoload too but no luck

I hope you find this helpful.
If you want to just show the first n characters of generated personal access token, try to change this.accessToken = accessToken to this.accessToken = accessToken.substring(1, n); in showAccessToken function of PersonalAccessTokens.vue

@RezaGhanbari Thanks but It is not just about displaying the token. I am creating a plugin to sell and the frontend of the plugin is in jquery and the backend API is in laravel. I want to limit the number of calls they make and authenticate the calls. So I will be providing my customers with an access token. This is too big to give as an access key. Would you suggest any other method for this approach? Thanks

See if this helps https://github.com/chrisbjr/api-guard @anbu369

@brunogaspar Thanks for that. That was the only good solution. But I wanted to stick with passport and I finally settled with client-credentials. Thanks :)

anbu, i am having the same issue where the token generate is approx 1071 characters. what was the solution to this if there was one?

@vcc3 Hi, there was no solution. The personal access token is always 1071 characters. Like I mentioned above, I started using client credentials. So when a user purchases my API, they get a client_id and client_secret. The user then uses them to get an access token. Then when the access token is used to access my API, I can retrieve the user information to monitor.

What if there was no backend language involved and user cannot go through the OAuth flow for creating access tokens? I am creating an API to be consumed in a Shopify theme and every customer who purchase the theme will be given an access token, but personal access token is very long. It will cause issues in ajax request ( get method ). Any other solution to this? Other than Passport? Thanks.

@awebartisan I am afraid not. Not that I know of. I ended up using passport client id and secret. Without using some custom backend logic, I dont think you can achieve that. But let me know if you find one :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rudolfdobias picture rudolfdobias  ·  3Comments

mehrancodes picture mehrancodes  ·  3Comments

mind-control picture mind-control  ·  3Comments

andcl picture andcl  ·  3Comments

huiyonghkw picture huiyonghkw  ·  3Comments