1
我正尝试使用自定义Ruby代码(从官方php库中移植到Azure)为我的Windows媒体服务文件创建SAS网址。该代码看起来像这样:签名与Azure SAS不匹配网址
def create_signature(path = '/', resource = 'b', permissions = 'r', start = '', expiry = '', identifier = '')
# If resource is a container, remove the last part (which is the filename)
path = path.split('/').reverse.drop(1).reverse.join('/') if resource == 'c'
canonicalizedResource = "/mediasvc78m7lfh2gnn2x/#{path}"
stringToSign = []
stringToSign << permissions
stringToSign << start
stringToSign << expiry
stringToSign << canonicalizedResource
stringToSign << identifier
stringToSign = stringToSign.join("\n")
signature = OpenSSL::HMAC.digest('sha256', wms_api_key, stringToSign.encode(Encoding::UTF_8))
signature = Base64.encode64(signature)
return signature
end
def createSignedQueryString(path = '/', query_string = '', resource = 'b', permissions = 'r', start = '', expiry = '', identifier = '')
base = 'https://mediasvc78m7lfh2gnn2x.blob.core.windows.net'
uri = Addressable::URI.new
# Parts
parts = {}
parts[:st] = URI.unescape(start) unless start == ''
parts[:se] = URI.unescape(expiry)
parts[:sr] = URI.unescape(resource)
parts[:sp] = URI.unescape(permissions)
parts[:si] = URI.unescape(identifier) unless identifier == ''
parts[:sig] = URI.unescape(create_signature(path, resource, permissions, start, expiry))
uri.query_values = parts
return "#{base}/#{path}?#{uri.query}"
end
当运行:
puts createSignedQueryString(
'asset-12514a3b-565f-4150-9543-e3c2b4531428/video.mp4',
nil,
'b',
'r',
(Time.now - 5*60).utc.iso8601,
(Time.now + 30*60).utc.iso8601
)
当我尝试我的浏览器指向它,我得到:
<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:ee7fd18f-cd1f-4179-8a58-c8b746d0549c Time:2014-02-20T12:29:27.0468171Z
</Message>
<AuthenticationErrorDetail>
Signature did not match. String to sign used was r 2014-02-20T12:24:19Z 2014-02-20T12:59:19Z /mediasvc78m7lfh2gnn2x/asset-12514a3b-565f-4150-9543-e3c2b4531428/video.mp4
</AuthenticationErrorDetail>
</Error>
你有什么想法什么可以导致该错误(或如何调试呢?),以及如何应对 接着就,随即?提前致谢。
谢谢你付出更多的帮助比支付天蓝色的支持:)无论如何,我使用“主要Windows媒体服务访问密钥”作为我的wms_api_key变量。当我试图使用它的代码时,它会抛出'unpack:无效的base64(ArgumentError)' – mbajur
我明白了。实际上,您需要将存储帐户密钥用于wms_api_key变量,而不是媒体服务访问密钥。 –
哦,好的。我没有任何信息应该用在那里,所以我用wms键试过。无论如何,它仍然会抛出同样的错误。新链接是https://mediasvc78m7lfh2gnn2x.blob.core.windows.net/asset-12514a3b-565f-4150-9543-e3c2b4531428/video.mp4?se=2014-02-25T09%3A21%3A28Z&sig=AV9nieaGkq1x3EXEvk3T2CQz0ZK41g9rwgxrTOjnnVs%3D%0A&sp = r&sr = b&st = 2014-02-25T08%3A46%3A28Z – mbajur