Sign In Register

How can we help you today?

Start a new topic
Answered

Credentials used by real time scripts requests

Hello


When using RTSession.newRequest() to make a request, such as a LogEvent, under what credentials is the request made?

The background of the question is that I want to have certain events that can only be called from real time cloud code, which is an authoritative server in my case. E.g. the "updatePlayerRank" event should only be possible to be called from RT cloud code.

Currently, all I'm getting is an "authentication": "NOTAUTHORIZED" error on the requests, no matter how I set the permissions.


Best Answer

Hi Christian


RealTime requests are sent with a system credential. So they are able to make any call.


I suspect you are not setting the playerId of the request before you are sending it. Leading to the NOTAUTHORIZED error.


RTSession.onPacket(123, function(packet){

    var currentPlayerId = packet.getSender().getPlayerId();

    RTSession.newRequest()

        .createLogEventRequest()

        .setEventKey("KEY")

        .setPlayerId(currentPlayerId)

        .send(function(response){

            //Process response    

    })

})


Hope that helps.


Answer

Hi Christian


RealTime requests are sent with a system credential. So they are able to make any call.


I suspect you are not setting the playerId of the request before you are sending it. Leading to the NOTAUTHORIZED error.


RTSession.onPacket(123, function(packet){

    var currentPlayerId = packet.getSender().getPlayerId();

    RTSession.newRequest()

        .createLogEventRequest()

        .setEventKey("KEY")

        .setPlayerId(currentPlayerId)

        .send(function(response){

            //Process response    

    })

})


Hope that helps.

Thanks for the prompt reply.

I see.

Indeed, I wasn't setting any player ID, precisely because I wanted the call to be made with system credentials instead of the player's.

BTW, the RTRequestBuilder is not documented at all, the only mention being "signature newRequest() returns RTRequestBuilder A builder object for creating and sending requests to the GameSparks platform".

Hi Cristan,


We've added a section to the Client API for the RT Scripts to help with this. You can find that page and the examples here. If you have any further questions just let us know.


Regards,

Liam

Hello


Does it matter which player ID I set for the request? For example, could I create a dummy player that will never actually play, but only use its ID for such calls?

Ran a test, seems to be working with a dummy player ID. Simply insert a record from the NoSQL page into the players collection (I've only defined the username), copy the generated ID and it seems to work just fine.

Login to post a comment