Home > Blockchain >  Azure AD is not returning token : Unknown Host Error
Azure AD is not returning token : Unknown Host Error

Time:10-20

I am trying to grant access to IoT Hub based on Azure AD. But when I try to get token, it is throwing this error in Postman enter image description here

CodePudding user response:

The resource field should be the static ID of all IoT Hub service principals. Try this instead of the hostname:

89d10474-74af-4874-99a7-c23c2f643083

CodePudding user response:

Here is another approach:

I tried to reproduce the same in my environment and got the results successfully like below:

I created an Azure AD application like below:

enter image description here

To generate token via Postman, I used the below parameters:

POST https://login.microsoftonline.com/TenantID/oauth2/token

client_id:14ad98e6-8b3d-4774-a2ad-XXXXX
client_secret:XXXXXX
resource:https://iothubs.azure.net
grant_type:client_credentials

Response:

enter image description here

When I decoded the above token, I can see the aud as https://iothubs.azure.net like below:

enter image description here

The 400 Bad request error usually occurs if you have passed any invalid URL while generating the token. Make sure to pass the valid parameters.

Try sending the request again in Postman and check if the access token is generated or not.

Alternatively, you can also replace the resource by 89d10474-74af-4874-99a7-c23c2f643083 as suggested by Matthijs van der Veer like below:

enter image description here

Decoded token Response:

enter image description here

  • Related