1

Looking for the convenience of Auth0 to sort out JWTs between my Angular 2 client and Laravel 5.3 API. I've followed (and double-checked that I've followed) Auth0's getting started guide:

https://auth0.com/docs/quickstart/backend/php-laravel

But can't seem to get it to authenticate me. When I curl as follows:

curl --request GET --url http://localhost/api/test --header 'authorization: auth0_id_token'

I get:

Unauthorized user curl: (6) Could not resolve host: auth0_id_token

In my \routes\api, I have:

Route::get('/test', array('middleware' => 'auth0.jwt', function() {
    return "Hello " . Auth0::jwtuser()->name;
}));

I'm generating the id_token using this:

https://auth0.com/docs/api/authentication#!#post--oauth-ro

and can see when I go to (https://manage.auth0.com/#/users) that Auth0 thinks the user has logged in.

Any pointers for where I should be looking to try and debug this?

theotherdy
  • 715
  • 1
  • 7
  • 22

1 Answers1

1

The correct way to include a bearer token in the HTTP Authorization header is to use the Bearer authentication scheme, so your header should be:

Authorization: Bearer [auth0_id_token]

Additionally, the error you received from curl also indicates that the command is not being parsed as you intended, more specifically, it seems 'authorization: auth0_id_token' is being parsed as multiple arguments which results in the auth0_id_token part being considered as an URL which will fail when trying to resolve the host; try to use double quotes instead.

João Angelo
  • 56,552
  • 12
  • 145
  • 147
  • Thanks so much @João Angelo. That was exactly the problem and, although I'd checked I had all the Laravel bits right, I hadn't spotted that my Curl was wrong. In case it helps anyone else, the working command is: curl --request GET --url localhost/api/test --header "Authorization: Bearer auth0_id_token". Thanks again. – theotherdy Nov 22 '16 at 09:44