Sign In Register

How can we help you today?

Start a new topic

Find playerId by authToken

I'm running a dedicated server to handle game logic (needed c++) and I'm running into a brick wall here.

The idea is that the client will authenticate through GameSparks and receive his authToken and playerId.  One that's done, the player connects to the dedicated server and sends his playerId for the server to use in games.

For security reasons, I cannot trust the playerId given to me by the javascript client, so I'd rather use the authToken instead and have the server look up the playerId based on that.

Creating a new Game Data Index to mirror authTokens is not a good option because I'll need to track many things like resetTokens(), etc.

I know playFab have something called GetPlayerIdFromAuthToken.  Is there any way to do this currently with GameSparks?

So there's a dirty little secret that Gamesparks will tell you not to use, but you can actually query the system collections with an undocumented API. The cloud code won't auto complete it. Basically you can access the system collections (where the 'player' collection is stored) the same as meta collections (read only) with Spark.systemCollection(collection_name).

So in your case I would do the following:

var playerId = getPlayerIdFromAuth(authToken);

function getPlayerIdFromAuth(authToken){
    var player = Spark.systemCollection("player").findOne({"authTokens" : authToken}, {"_id" : 1});
        return null;
    return player["_id"]["$oid"];


Don't tell Gamesparks I told you 

Works perfectly!  THANK you!

1 person likes this
Login to post a comment