I have the below code to get the authorization ids of the Service bus and Queue separately
$auth_Ids = (Get-AzServiceBusAuthorizationRule -ResourceGroupName $ResourceGroupName -NamespaceName $NamespaceName).Id
$auth_Id = ($auth_Ids[1] | Out-String)
Running the above gives me Service Bus SAS Policy authorization Id
/subscriptions/XXX/resourcegroups/YYY/providers/Microsoft.ServiceBus/namespaces/YYY-asb/authorizationrules/SASPolicy
Now to get the queue auth id
$qauth_Id = (Get-AzServiceBusAuthorizationRule -ResourceGroupName $ResourceGroupName -NamespaceName $NamespaceName -QueueName $QueueName).Id
Running the above gives me QUEUE SAS Policy authorization Id
/subscriptions/XXX/resourcegroups/YYY/providers/Microsoft.ServiceBus/namespaces/YYY-asb/queues/qname/authorizationrules/Policy
Only difference between the auth_ids is queues/qname/
Now when I call the New-AzServiceBusAuthorizationRuleSASToken to generate a SAS Token the call with queue auth_id works.
This works (qauth_id from queue)
$sastoken = (New-AzServiceBusAuthorizationRuleSASToken -AuthorizationRuleId $qauth_Id -KeyType $PolicyName -ExpiryTime $endtime).SharedAccessSignature
This doesn't (auth_id from service bus)
$sastoken = (New-AzServiceBusAuthorizationRuleSASToken -AuthorizationRuleId $auth_Id -KeyType $PolicyName -ExpiryTime $endtime).SharedAccessSignature
Unexpected character encountered while parsing value: <. Path '', line | 0, position 0.
I am not sure how to get SAS token to the service bus itself rather than the queue/topic. Do I have to create SAS Policy on each queue or topic to get the SAS token or the SAS Policy at the service bus level is sufficient?
The error may be you are passing the
AuthorizationruleIdIncorrect format in theNew-AzServiceBusAuthorizationRuleSASTokencommand.First I tried AuthorizationruleId with the below command:
Output:
Now I tried with the below command to create an
SAStoken using the aboveauth_IdCommand:
Output:
Total output:
The above command executes and creates the
SAStoken at the namespace level.Reference:
New-AzServiceBusAuthorizationRuleSASToken (Az.ServiceBus) | Microsoft Learn