Integration between GameSparks and GameLift

Hey there, here we go for another question from me.

To integrate GameSparks with GameLift, I was following this thread. In one of @Al…Murray posts, we can find 4398-gamelift-rest-call.txt (13.5 KB)this script which, using crypto-js, prepares us an HTTP POST request to AWS, with the properly signed headers and so on.
It has one problem though: GameSparks doesn’t support Crypto-JS. And thanks to this, I had to adapt it to GameSparks reality, resulting in this script. And this is the script I’m using to perform the actual calls.

Now that the script is running correctly when submitting the request, I receive a 400 response with the following error:

    {
"__type": "InvalidSignatureException",
"message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."
}

Mhm. Clear enough, right?

After the first time I received this error, I jumped into your own documentation to make sure the Signature Version 4 was being properly built. A few things had to be repaired, yes, nothing substantial, but in the end, the output from the request is still the same: unsuccessful, incompatible signatures.

I have no idea on how to proceed with this. This seems to be the only way I can get GameSparks and GameLift integrated and my brain is not functioning correctly to highlight where the problem exactly is.

Given this background, I shall ask you - what can I do?

Thanks,
Guilherme.

Hey @chiefGui,

As @Al…Murray suspects, it should be possible to get your script working without the need to import Crypto-JS.

I saw in your script that you were using GameSparks SparkDigest with hex-encoded HMAC-SHA256. AWS API’s require that they are signed with base64-encoded HMAC-SHA256.

SparkDigest does support this, I have edited your script to use base64 encoding which I think will get you closer to getting a successful response from the API. I have also tested some API calls to AWS from GameSparks using this encoding with success.

I think it’s worth trying this before importing Crypto-JS as it will keep the number of dependencies lower for your script.

Please get in touch and let us know how you get on!

Hey @chiefGui,

I have just been in touch with our support team for you. They are taking a look at this and will come back to you as soon as possible with further info. The team will respond via the GameSparks support ticket that you have open there already.

Have a great weekend!

Hey @chiefGui,

Yes, the signature is incorrect.

Source for those Crypto-JS functions can be downloaded from the link given in the other thread, specifically:

code.google.com/p/crypto-js

Then you can download that and paste the source from the functions in the cloud code, using code from the two files I indicate, sha256.js and sha256hmac.js.

The files are here for your convenience. 4410-sha256.zip (5.8 KB)sha256.zip

I think you used a Gamesparks function instead. I don’t know if that does the same thing or something different.

Give it a go, and if not, then I will see if I can’t fix the script here when I have a bit more time.

Thank you!

Hello!
Thank you for your answers.

Well, I have tried your script @peterc and had to make some adaptations to it in order to make it work. Fundamentally I’ve just changed .hmacSha256Base64 to .sha256Base64 from a few places otherwise I was not being able to run the code. This is the final result of the script.

Unfortunately, I still have the same output, which lead me to test if my access/secret keys are working properly.

I just opened the IAM Policy Simulator and…

… yes, seems that everything’s normal. I’m using the same keys as the user tested in the screenshot above.

Let me ask you: are the scripts you used to perform the HTTP request the same ones we’re using here, in this thread?

Am gonna try CryptoJS. Let’s see how it goes.

Hey guys,

I’ve implemented CryptoJS in GameSparks and readapted the script properly. The request is made, but the output is still the same (submitted through Cloud Code from GameSparks):

      "result": {
"statusCode": 400,
"headers": {
"x-amzn-RequestId": "f1ef7e7e-342c-11e8-8fda-3341ffb13e15",
"Connection": "close",
"Date": "Fri, 30 Mar 2018 15:13:46 GMT",
"Content-Type": "application/x-amz-json-1.1"
},
"data": {
"__type": "InvalidSignatureException",
"message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."
}
}

This is the script that makes the call and this is the AWSRequest.js (with CryptoJS). The CryptoJS scripts I’m using are the same you attached here @Al…Murray (hmacSha256, sha256).

Maybe it’s also important to note that I get the same response if I make the request via Postman or cURL.

At this point, I don’t know what else I can do.

Suggestions?

Thank you, @peterc. Really appreciate the dedication you’re putting on this.

Have a great weekend you too and happy holidays!

Hey guys,

a representative of GameSparks have answered my question and we made this integration successfully work.

The resolution is here.

Though I’m sure GameSparks will, at some point, release an official approach to integrate the two services, I’m also sure I’ll be fine with this for now.

Thank you @peterc and @Al…Murray for all the efforts you’ve put into this. Without your answers and attention to my problem, I have no doubt this wouldn’t be possible.

Best regards,
Guilherme.

Hi @chiefGui,

Happy to help! I am really glad you got the script working with the support team. Thanks very much for sharing the code!

Hi, its your ticket, so only you have access to this ticket. :wink:

@chiefGui Can you provide solution? ticked is private

Hey @BorMor, @Damiann, @chiefGui

I posted sample code for the solution here. There is also a how-to video and the sample files (again) posted here because it was too big for the forum. (Link time limited to 1/31/2020 but I can update it periodically.) I show the process required to install the attached source into GameSparks, test it, and a run-through of what it does.

Thank you,

Al Murray :slight_smile:

Hey everyone,

I really want to apologize for the late response to this thread. We’ve been busy making the final adjustments to our game and I wasn’t able to touch in the GameLift integration subject for a while.

Also, sorry about the ticket-privacy-thing–I thought it was visible to everyone.

Hope you all got your questions clarified, and a special thanks to @Al…Murray that spent some time giving some attention on this GameSparks + GameLift integration. Excellent video, by the way.

Just one question @Al…Murray: can you make, somehow, this video gain more visibility? I think it has an immense value and it’s currently way too hidden.

Thanks,
Guilherme.

@chiefGui yes, I am escalating this request to the marketing team who deals with this type of thing.

Thank you!

Al :slight_smile:

Hey everyone, just a heads up that I’ve created a repository on GitHub with instructions and versioned files to make our lives easier regarding GameLift + GameSparks integration.

https://github.com/chiefGui/sparkslift.js

The code used there is mostly the one @Al…Murray have written with some adaptations. Have tested here and it’s working perfectly. Also, everyone is welcomed to contribute to make that code better while we don’t have an official form of integration.

Also, Amazon, if my repository goes against any of your policies, just let me know that I won’t hesitate to shut it down.

Best regards,
Guilherme.

Hi Al,

Apparently access to the material you have linked has expired. Would it be possible to update it?

@Heinis Fixed. Please let me know if you have further problems.

Thank you very much!

The OP provided a great GitHub project here:

https://github.com/chiefGui/sparkslift.js

Thank you,

Al Murray :slight_smile: