Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidAudience: Unable to authenticate to Hybrid Connection #100

Open
cawoodm opened this issue Oct 28, 2024 · 0 comments
Open

InvalidAudience: Unable to authenticate to Hybrid Connection #100

cawoodm opened this issue Oct 28, 2024 · 0 comments

Comments

@cawoodm
Copy link

cawoodm commented Oct 28, 2024

We created a connection with 2 SAS Policies "defaultSender" and "defaultListener" and are unable to connect. The undocumented and inexplicable error is:

InvalidAudience: The authorization header contains a token with a wrong audience.

Image

[Reflection.Assembly]::LoadWithPartialName("System.Web") | out-null
$URI = "our-servicebus-name.defaultSender.windows.net"
$Access_Policy_Name = "defaultSender"
$Access_Policy_Key = "<primaryKey>"
$Expires = ([DateTimeOffset]::Now.ToUnixTimeSeconds()) + 300
$SignatureString = [System.Web.HttpUtility]::UrlEncode($URI) + "`n" + [string]$Expires
$HMAC = New-Object System.Security.Cryptography.HMACSHA256
$HMAC.key = [Text.Encoding]::ASCII.GetBytes($Access_Policy_Key)
$Signature = $HMAC.ComputeHash([Text.Encoding]::ASCII.GetBytes($SignatureString))
$Signature = [Convert]::ToBase64String($Signature)
$SASToken = "SharedAccessSignature sr=" + [System.Web.HttpUtility]::UrlEncode($URI) + "&sig=" + [System.Web.HttpUtility]::UrlEncode($Signature) + "&se=" + $Expires + "&skn=" + $Access_Policy_Name
$SASToken

This produces: SharedAccessSignature sr=our-servicebus-name.defaultSender.windows.net&sig=***&se=1730135799&skn=defaultSender

Nowhere in Azure Portal near Hybrid Connections is any explanation of how to generate an SAS nor how to pass one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant