Skip to main content

Checking mobile token by Game Server after authorization

This is a sample code that implements last step of authorization process - checking mobile token by Game Server.

You need send access_token from your mobile application to Game Server and check it in our Authorization server. If checking is successful you'll receive in response user account data.

$access_token = $_POST['access_token'];    // From mobile client
$request = [
'http' => [
'header' => 'Authorization: Bearer ' . $access_token, // You must use access_token in header
'method' => 'GET',
],
];
$context = stream_context_create($request);
$response = file_get_contents('https://auth.101xp.com/tokens/mobile', false, $context);
if ($response === false) {
$result = [
'status' => 'error',
'error_message' => 'Wrong API response.',
];
} else {
$response = json_decode($response, true);
if($response['status'] == 'success'){
$account_id = $response['mobile']['id']; // You need to use it to create ingame user account
if(!empty($response['portal'])){
// You can use Portal account data to personalize game account
$user_id = $response['portal']['id'];
$user_name = $response['portal']['display_name'];
$user_avatar = $response['portal']['photo'];
}

// Your other code here

$result = [
'status' => 'success',
'data' => [
'data',
'for',
'game',
'client',
],
];
} else {
$result = [
'status' => 'error',
'error_message' => 'Response contain errors.',
];
}
}
echo json_encode($result);