3

I am trying to build APIS in laravel 5.6, and for api authentication I am using laravel basic API token authentication.

For get request or post request, I need to pass api_token in the query parameter. Is there any way where I can pass the api_token in the header instead of url string?

I followed Laravel - Send api_token within the header .

For GET endpoint, my api url is like this

http://localhost:8000/api/category-list?api_token=YDYsOgkSIOWDdE1NG3Ih1yCkciatOPvtpF1gXTmy8GL1r72mcDEgNDkkZ5jh&Accept=application%2Fjson

For POST my parameter are like this

enter image description here

As you can see, for get I need to add the api token in the url, and for POST I need to add in the body. If I add the api token in the header, it says unauthorized access.

Header setting where authorization does not work enter image description here

6
  • please add code or request example to your question. Commented Jun 2, 2018 at 15:11
  • @AndriyLozynskiy hi, i updated the question with end point and image Commented Jun 2, 2018 at 15:34
  • @user7747472 For your get and post request what are you using to send the request on the client side? Something like axios? Commented Jun 2, 2018 at 17:22
  • @user7747472 your updates don't help because you show request that works. Please show headers section for request where authorization doesn't work. Commented Jun 2, 2018 at 18:13
  • @AndriyLozynskiy i added another screenshot where authorization does not work. Commented Jun 3, 2018 at 6:59

1 Answer 1

3

When you send api token through header the name of the header should be Authorization not api_token. Also prepend the type of token Bearer to authorization header.

So finally the header should look like:

Authorization: Bearer aEzKClugYHJQsr6If48i1y24KneTT7YwMtNrri7JNhGyEIbJv6YP5SrsFXx2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.