I am trying to get Dynamics 365 online data using access token received on successful authentication by using client credentials for an Web app / API application . However getting 401 always.
Here is what I am doing:
- Authentication
Request URL:
POST https://login.microsoftonline.com/tenantId/oauth2/tokenRequest Headers:
Content-Type: application/x-www-form-urlencoded
Accept: application/jsonRequest Body:
client_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
resource: domain.crm.dynamics.com
grant_type: client_credentials
client_secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx=Response Status: 200 OK
Response Body (Sample):
{
"token_type": "Bearer",
"expires_in": "3599",
"ext_expires_in": "0",
"expires_on": "1524644921",
"not_before": "1524641021",
"resource": "domain.crm.dynamics.com",
"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
} - Request a Dynamics resource using the received access_token
Request URL:
GET https://domain.crm.dynamics.com/api/data/v8.2/accounts?$select=nameRequest Headers:
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Authorization: Bearer {{access_token}}Response Status: 401 Unauthorized
Response Body: HTTP Error 401 - Unauthorized: Access is denied
Response Headers:
WWW-Authenticate: Bearer authorization_uri=https://login.windows.net/tenantId/oauth2/authorize, resource_id=domain.crm.dynamics.com
*This post is locked for comments