0
votes

Getting the below error while making a call to Create Container.

Response Code : 403 Response Message : Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

String stringToSign = "PUT\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" + date + "\nx-ms-version:" + "2018-03-28\nx-ms-lease-action:acquire\nx-ms-lease-duration:1\nx-ms-proposed-lease-id:1f812371-a41d-49e6-b123-f4b542e851c5\n" + "/" + storageAccount + "/"+ "container-lease-test"+"\ncomp:lease";

Java code snippet

HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection();
connection.setRequestMethod(vMethod);
connection.addRequestProperty("Authorization", authHeader);
connection.addRequestProperty("x-ms-date", date);
connection.addRequestProperty("x-ms-version", "2018-03-28");
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(0);

//Create Lease
connection.addRequestProperty("x-ms-lease-action", "acquire");
connection.addRequestProperty("x-ms-lease-duration","1");
connection.addRequestProperty("x-ms-proposed-lease-id","1f812371-a41d-49e6-b123-f4b542e851c5");
1

1 Answers

1
votes

We need to sort the x-ms-* headers lexicographically by header name, in ascending order. And also you missed restype at the end.

String stringToSign = "PUT\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" + date + "\nx-ms-lease-action:acquire\nx-ms-lease-duration:15\nx-ms-proposed-lease-id:1f812371-a41d-49e6-b123-f4b542e851c5\nx-ms-version:2018-03-28\n/" + storageAccount + "/container-lease-test\ncomp:lease\nrestype:container";

Besides, x-ms-lease-duration should be 15~60 or -1(infinite).

I recommend you to follow docs and use Fiddler to catch traffic, you can see expected stringtosign if you get 403 error. Then you can enjoy quick debug.