Skip to content
Advertisement

Authenticating requests to azure’s batch REST interface (php)

I’m trying to authenticate against azures batch REST interface from my php server. According to the docs (https://docs.microsoft.com/en-us/rest/api/batchservice/authenticate-requests-to-the-azure-batch-service) I came up with this function:

JavaScript

However, I always get a 403 error:

“Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature”

Due to the complicated setup and the vague error message, I have a really hard time to figure out, where/why it’s failing. Tried tweaking every option I could think of, but no. What am I missing here?

Update: I managed to convert the batch auth lib from the official python sdk into php. This is what I came up with:

JavaScript

I ran some tests, for the signing process with a “test-string” in both, the (working) python example and my php script. The signature is the same, so my signing function now definitely works!

I also compared headers and the string to sign. They are the same!

And yet in php it throws a 403 error, telling me

The MAC signature found in the HTTP request ‘mySignatureCode’ is not the same as any computed signature.

Advertisement

Answer

Took me a week to figure it out, it was the content-type header, that guzzle automatically sets if you don’t specify it.

I post my whole script in case anyone else ever wants to do the same – no need to suffer too – it should work fine now:

JavaScript

And you use it like this for POST:

JavaScript

And like this for GET etc:

JavaScript

Just make sure, the content-type in your headers and in your signature string match.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement