如何在服务器端验证 FBInstant.context.getID() 以确保它没有被伪造?
How to verify FBInstant.context.getID() on the server side to ensure it is not faked?
我有一个“Facebook Web Games”格式的多人文字游戏,想将其移植到“Instant Games”。
可以使用 FBInstant.player.getID();
获取玩家 ID,然后我可以在我的游戏后端服务器上调用 URL,如下所示:
FBInstant.startGameAsync()
.then(function() {
var playerName = FBInstant.player.getName();
var playerPic = FBInstant.player.getPhoto();
var playerId = FBInstant.player.getID();
$.post("/my/game/backend", { playerID: playerID });
});
但是我不明白,如何在我的后端服务器上验证播放器 ID。
如果我不这样做,其他人就可以使用 curl
获取 URL“/my/game/backend”并冒充其他玩家。
肯定有某种签名或token,可以通过一个common secret传递给游戏后台服务器进行验证,但是我在Instant Games documentation中还没有找到。
https://developers.facebook.com/docs/games/instant-games/sdk/fbinstant6.3#signedplayerinfo
SignedPlayerInfo
Represents information about the player along with a signature to verify that it indeed comes from Facebook.
您需要使用 getSignedPlayerInfoAsync
,然后您可以从中获取签名,并将该值发送到您的服务器以在那里进行验证。
我有一个“Facebook Web Games”格式的多人文字游戏,想将其移植到“Instant Games”。
可以使用 FBInstant.player.getID();
获取玩家 ID,然后我可以在我的游戏后端服务器上调用 URL,如下所示:
FBInstant.startGameAsync()
.then(function() {
var playerName = FBInstant.player.getName();
var playerPic = FBInstant.player.getPhoto();
var playerId = FBInstant.player.getID();
$.post("/my/game/backend", { playerID: playerID });
});
但是我不明白,如何在我的后端服务器上验证播放器 ID。
如果我不这样做,其他人就可以使用 curl
获取 URL“/my/game/backend”并冒充其他玩家。
肯定有某种签名或token,可以通过一个common secret传递给游戏后台服务器进行验证,但是我在Instant Games documentation中还没有找到。
https://developers.facebook.com/docs/games/instant-games/sdk/fbinstant6.3#signedplayerinfo
SignedPlayerInfo
Represents information about the player along with a signature to verify that it indeed comes from Facebook.
您需要使用 getSignedPlayerInfoAsync
,然后您可以从中获取签名,并将该值发送到您的服务器以在那里进行验证。