1

How can I put client id and client secret into httprequest?

           /*
            curl -X POST -H "Content-Type: application/json" \
           --user "<client_id>:<client_secret>" \
        -d '{"grant_type": "client_credentials", "scope": "public"}' \
        'https://api.lyft.com/oauth/token'
      */

  URL url = new URL("https://api.lyft.com/oauth/token");
           HttpURLConnection conn = (HttpURLConnection) url.openConnection();
           conn.setRequestProperty("Content-Type", "application/json");
           conn.setRequestProperty("grant_type", "client_credentials");
           conn.setRequestProperty("scope", "public");
           //conn.setRequestProperty("Authorization", "Token token=" + accessToken);
           conn.setRequestMethod("POST");

Getting httpStatus : 400

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ramesh Chandra
  • 32
  • 2
  • 10

1 Answers1

0

Content-Type should be application/x-www-form-urlencoded. See 4.4.2. Access Token Request of RFC 6749 (The OAuth 2.0 Authorization Framework) for details.

Community
  • 1
  • 1
Takahiko Kawasaki
  • 18,118
  • 9
  • 62
  • 105