skip to Main Content

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

####### Update ######
I have already created the Application in Azure AD
enter image description here
enter image description here

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search