'Azure AD API authentication : invalid_token, The audience 'https://webpubsub.azure.com/' is invalid

I'm new in Azure, I try to connect to my first webpubsub service with curl from my webserver :

curl -X POST -d 'grant_type=client_credentials
&client_id=d13xxxxx
&client_secret=zi5xxxxx
&resource=https%3A%2F%2Fwebpubsub.azure.com%2F' 
https://login.microsoftonline.com/a93xxxxx/oauth2/token

and obtain :

{
"token_type":"Bearer",
"expires_in":"3599",
"ext_expires_in":"3599",
"expires_on":"1648200799",
"not_before":"1648196899",
"resource":"https://webpubsub.azure.com/",
"access_token":"eyJxxxxx"
}

But when I want to use this token :

curl -I -H "Authorization: Bearer eyJxxxxx"
https://my-resource.webpubsub.azure.com/api/hubs/myHub1/users/user1?api-version=2021-10-01

I only obtain :

HTTP/2 401 
www-authenticate: Bearer error="invalid_token",
error_description="The audience 'https://webpubsub.azure.com/' is invalid"

I'm lost in technical vocabulary in AD documentation and I don't understand what is wrong or missing.

Anyone to help me, please ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source