我在 Azure 门户中创建了一个服务总线/通知中心。
现在我正在尝试将 Azure REST API 与 一起使用 postman 基于此文档:
https://msdn.microsoft.com/en-us/library/azure/dn223265.aspx
这是我的 postman 配置:
这是一个 发布 以下网址的方法(创建注册)
https://mysite.servicebus.windows.net/mysite-notif/registrations/?api-version=2015-01
(出于隐私原因,我在该网址中替换了 mysite)
在 标题 ,我输入了 2 个条目:
内容类型
应用程序/atom+xml;type=entry;charset=utf-8
授权
Endpoint=sb://[mysite].servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=[mykey]
(这个连接信息是我从 Azure 门户复制的)
在 正文 ,我选择了 raw - XML(txt/xml) 并粘贴了:
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<WindowsRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag, myOtherTag</Tags>
<ChannelUri>{ChannelUri}</ChannelUri>
</WindowsRegistrationDescription>
</content>
</entry>
(这是 Windows 通知服务的 native 注册示例)
当我从 Postman 内部发送此电话时,我收到了 401 错误 :
<Error>
<Code>401</Code>
<Detail>MalformedToken: The credentials contained in the authorization header are not in the WRAP format..TrackingId:ee0d87ef-6175-46a1-9b35-6c31eed6049d_G2,TimeStamp:8/13/2015 9:58:26 AM</Detail>
</Error>
我错过了什么?
是我在 Postman 的“No Auth”上留下的授权选项卡吗?
授权 header 的值是否应该像此处所示进行编码?
Creating registration ID for Azure Notification Hub via REST api
谢谢。
最佳答案
您的 《授权》标题不正确。
如 Azure Notification Hubs REST API documentation, e.g. for creating a registration 中所述, 《授权》 header 必须包含“按照使用服务总线的共享访问签名身份验证中指定的方式生成的 token ”...
token 格式在 Shared Access Signature Authentication with Service Bus 的文档中指定如下:
SharedAccessSignature sig=<signature-string>&se=<expiry>&skn=<keyName>&sr=<URL-encoded-resourceURI>
URL-encoded-resourceURI
:您将 POST 请求发送到的网址(在您的情况下为“https://mysite.servicebus.windows.net/mysite-notif/registrations/?api-version=2015-01”)keyName
:在您的情况下,默认 key 名称“DefaultFullSharedAccessSignature”expiry
:到期时间表示为自 1970 年 1 月 1 日 00:00:00 UTC 纪元以来的秒数。signature-string
:SAS token 的签名是使用授权规则的 PrimaryKey 属性使用待签名字符串的 HMAC-SHA256 计算的。 string-to-sign 由一个资源 URI 和一个到期时间组成,格式如下:StringToSign = <resourceURI> + "\n" + expiry;
resourceURI
应该与 URL-encoded-resourceURI
相同(也是 URL 编码的)StringToSign
的HMAC-SHA256使用 SAS key (在您的示例中用 [mykey] 替换)。使用 signature-string
的 URL 编码结果那么。 关于api - 在 Postman 中为 Azure 通知中心创建注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31988204/