com.playfab.PlayFabAuthenticationAPI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of server-sdk Show documentation
Show all versions of server-sdk Show documentation
PlayFab is the unified backend platform for games — everything you need to build and operate your game, all in one place, so you can focus on creating and delivering a great player experience.
package com.playfab;
import com.playfab.internal.*;
import com.playfab.PlayFabAuthenticationModels.*;
import com.playfab.PlayFabErrors.*;
import com.playfab.PlayFabSettings;
import java.util.concurrent.*;
import java.util.*;
import com.google.gson.*;
import com.google.gson.reflect.*;
/**
* The Authentication APIs provide a convenient way to convert classic authentication responses into entity authentication
* models. These APIs will provide you with the entity authentication token needed for subsequent Entity API calls.
*/
public class PlayFabAuthenticationAPI {
private static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create();
/**
* Method to exchange a legacy AuthenticationTicket or title SecretKey for an Entity Token or to refresh a still valid
* Entity Token.
* @param request GetEntityTokenRequest
* @return Async Task will return GetEntityTokenResponse
*/
@SuppressWarnings("unchecked")
public static FutureTask> GetEntityTokenAsync(final GetEntityTokenRequest request) {
return new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privateGetEntityTokenAsync(request);
}
});
}
/**
* Method to exchange a legacy AuthenticationTicket or title SecretKey for an Entity Token or to refresh a still valid
* Entity Token.
* @param request GetEntityTokenRequest
* @return GetEntityTokenResponse
*/
@SuppressWarnings("unchecked")
public static PlayFabResult GetEntityToken(final GetEntityTokenRequest request) {
FutureTask> task = new FutureTask(new Callable>() {
public PlayFabResult call() throws Exception {
return privateGetEntityTokenAsync(request);
}
});
try {
task.run();
return task.get();
} catch(Exception e) {
return null;
}
}
/**
* Method to exchange a legacy AuthenticationTicket or title SecretKey for an Entity Token or to refresh a still valid
* Entity Token.
*/
@SuppressWarnings("unchecked")
private static PlayFabResult privateGetEntityTokenAsync(final GetEntityTokenRequest request) throws Exception {
String authKey = null, authValue = null;
if (PlayFabSettings.EntityToken != null) { authKey = "X-EntityToken"; authValue = PlayFabSettings.EntityToken; }
else if (PlayFabSettings.ClientSessionTicket != null) { authKey = "X-Authorization"; authValue = PlayFabSettings.ClientSessionTicket; }
else if (PlayFabSettings.DeveloperSecretKey != null) { authKey = "X-SecretKey"; authValue = PlayFabSettings.DeveloperSecretKey; }
FutureTask