Following this example.
When I send a command to the website as thus, it works and returns a token:
[idf@xxxx ~]$ curl -d "name=Ivan&email=idf@xxxcom&password=secret" -H "Content-Type: application/x-www-form-urlencoded" -X POST localhost:3002/api/auth/register
{"auth":true,"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVhNzIwYzZkYzI2ZjNlNzRhMjZhODg1YiIsImlhdCI6MTUxNzQyMzcyNSwiZXhwIjoxNTE3NTEwMTI1fQ.W_lffqIlGh21UD2o4Sqd6mISrAC6PKv6swTQvQV1IfU"}
[idf@xxxx ~]$
I am then supposed to use this token to GET
some information about the user. I tried this:
[idf@xxx ~]$ curl -v -d "x-access-token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVhNzIwODlhNGZkZTViNzM5N2M1YjQ5YiIsImlhdCI6MTUxNzQyMjc0NiwiZXhwIjoxNTE3NTA5MTQ2fQ.7a5KPDvB-13KYrAfkBa_2-d3XKru1J1OkxWlofnxhFw" -H "Content-Type: application/x-www-form-urlencoded" -X GET localhost:3002/api/auth/me
* About to connect() to localhost port 3002 (#0)
* Trying ::1...
* Connected to localhost (::1) port 3002 (#0)
> GET /api/auth/me HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:3002
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 186
>
* upload completely sent off: 186 out of 186 bytes
< HTTP/1.1 403 Forbidden
< X-Powered-By: Express
< Content-Type: application/json; charset=utf-8
< Content-Length: 45
< ETag: W/"2d-vj/ohbytTg+R1uXxU34fCnv4o0o"
< Date: Wed, 31 Jan 2018 18:29:45 GMT
< Connection: keep-alive
<
* Connection #0 to host localhost left intact
[idf@xxxx ~]$
But it comes back with:
{"auth":false,"message":"No token provided."}
[idf@xxxx ~]$
I am almost certainly using curl
incorrectly to pass a parameter to GET
. What is the correct way to form the curl GET
string?