Getting an OAuth2 access token using “client credentials” does not require interactivity with a browser

The “client credentials” OAuth2 flow is allowed by many REST API’s for the case where a program is running in a non-interactive environment. It’s simply an HTTP POST where the client_id and client_secret are sent, and the OAuth2 access token is returned.

If you have a sample CURL statement that demonstrates how to do it, you can generate Chilkat source code from the CURL statement. For example, you might have CURL like this:

curl -X POST \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" \
  https://api.example.com/oauth/token

Go to https://tools.chilkat.io/curlHttp and copy the CURL statement into the tool. Also choose a JSON response, and copy the following into the Sample Response Body:

{
  "access_token": "YOUR_ACCESS_TOKEN",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "YOUR_REFRESH_TOKEN",
  "scope": "scope1 scope2"
}

Then generate the code in the programming language of your choice.

Tags :