How to implement access token in laravel code instead using it in header of postman?

Viewed 76

I have created an API in Laravel using Passport. Everything is working fine, generating the access token and using the token in Postman to show the data.

When the user logs in, I save the access token in the Users table. The problem is that I have to manually pass the access token in the Postman's header.

How can I pass the generated access token automatically to the header, or anywhere I need?

1 Answers

You can't let postman know that it must take a token from X url and add it to the others requests... what you can do is use a variable (inside postman) so you use that login url and copy paste the value of the token in that variable, so any request uses that variable it will automatically use the correct value (token). There is other way, sort of automation but it is overkill and way more complex and I have not the expertise for that... Learn more about Postman variables here.

In that same URL, there is something about scripting this (it would mean somehow like automate, like what you want), so read this.

Related