简体   繁体   中英

How do you get an access token from azure active directory (V2) to allow access to Azure Service Bus?

I've been following the this tutoral to get an access token for azure service bus so that I can post messages to a queue using Postman:

https://docs.microsoft.com/en-us/rest/api/servicebus/get-azure-active-directory-tokenTh

Following the example through works and I can get an access token. However, the example uses the older v1 token endpoints eg

https://login.microsoftonline.com/{{tennant-id}}/oauth2/token

I want to use the current v2 endpoint eg

https://login.microsoftonline.com/{{tennant-id}}/oauth2/v2.0/token

But when I switch get this error:

AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid. The scope https://servicebus.azure.net is not valid.

I'm assuming that the name of the scope must have changed and I cannot find any documentation about what scopes are for azure services. I've tried a bunch of things such as https://servicebus.windows.net and https://myqueue.servicebus.windows.net and googling but I've found nothing.

Update

Following on from the answers provided I have appended ".default" to the requested scope. This hasn't solved to the problem but has changed the error message I now get Error: invalid_client in the postman console.

I'm trying with the postman "get new access token" feature and have set it like this

[ 邮递员截图1

Update 2

Grant type was wrong in the last update - should be client credentials then it will work.

When using v2.0 endpoint of the client credential flow , you need to use scope instead of resource in the request body, and pass the /.default to the url, it should be https://servicebus.azure.net/.default .

Sample:

在此处输入图像描述

Mostly you might have missed to add.default in the scope parameter. Please try appending.default that is https://servicebus.azure.net/.default for scope parameter value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM