我辛苦了一个星期,现在要生成一个SAS令牌。但是我仍然无法通过授权。
以下是我得到的错误
<?xml version="1.0" encoding="utf-8"?>
<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:854b47a8-e01e-004e-2746-fc3888000000
Time:2020-03-17T10:26:29.3224986Z</Message>
<AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail>
</Error>
以下是使用Salesforce APEX的简单方法。我已经隐藏了帐户密钥
public void generateSASToken()
{
string storageKey = 'XXXXXXXXXXXFbF9ndVdcdl==';
Datetime sasExpiry = Datetime.now();
sasExpiry.addMinutes(15);
sasExpiry = getUTCDateTime(sasExpiry);
System.debug('sasExpiry-->'+sasExpiry);
String url='https://zaindevtesting.blob.core.windows.net/zaindevblob/test.txt?sv=2019-02-02&ss=bfqt&srt=sco&sp=w&se=2020-03-18T15:56:39Z&st=2020-03-17T07:56:39Z&spr=https&sig=';
String stringToSign = 'w\n2020-03-17T07:56:39Z\n2020-03-18T15:56:39Z\n/zaindevtesting/zaindevblob\nYWJjZGVmZw==\n2019-02-02';
String signature = '';
Blob unicodeKey = EncodingUtil.base64Decode(storageKey);
Blob data = Crypto.generateMac('HMACSHA256', Blob.valueOf(stringToSign), unicodeKey);
signature = EncodingUtil.base64Encode(data);
url = url + signature;
System.debug('signature--->'+url);
System.debug('signature--->'+signature);
}
我正在使用以下Microsoft文档 https://docs.microsoft.com/en-gb/rest/api/storageservices/service-sas-examples
请帮助我,我不介意有人提出替代解决方案。
谢谢, Zain