Search code examples
postcurlbasic-authentication

Curl command correct usage


I am trying to request an authentication token from a service using basic auth, Here is how I build the curl command

curl -H "Authorization:Basic <base64 encoding user:pass>=" -H "Content-Type:application/x-www-form-urlencoded" -X POST -d "grant_type=basic" http://auth.mydomain.com/v1/oauth2/token

This returns a 404, I have tried to check if the api exists by using the follwong

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://auth.mydomain.com/v1/oauth2/token
HTTP/1.1 401 Unauthorized
Server: nginx
Date: Thu, 16 Jun 2016 19:56:39 GMT
Content-Type: application/json
Content-Length: 62
Connection: keep-alive

What am I missing?


Solution

  • It would be easier to use the cURL -u option to specify <username>:<password in cleartext rather than base64-encoding it yourself directly in to an Authorization header.

    Furthermore it looks like you're constructing an OAuth 2.0 token request, but there's no such thing in the specification as an basic grant type.