Skip to content

Commit f763ab5

Browse files
https://api.playfab.com/releaseNotes/#180809
1 parent c66ac5f commit f763ab5

File tree

89 files changed

+13748
-7645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+13748
-7645
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.playfab;
2+
3+
import com.playfab.internal.*;
4+
import com.playfab.PlayFabAuthenticationModels.*;
5+
import com.playfab.PlayFabErrors.*;
6+
import com.playfab.PlayFabSettings;
7+
import java.util.concurrent.*;
8+
import java.util.*;
9+
import com.google.gson.*;
10+
import com.google.gson.reflect.*;
11+
12+
/**
13+
* The Authentication API group is currently in-progress. The current GetEntityToken method is a stop-gap to convert
14+
* another authentication into an Entity Authentication. See https://api.playfab.com/documentation/client#Authentication
15+
* for the other authentication methods.
16+
*/
17+
public class PlayFabAuthenticationAPI {
18+
private static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create();
19+
20+
/**
21+
* Method to exchange a legacy AuthenticationTicket or title SecretKey for an Entity Token or to refresh a still valid
22+
* Entity Token.
23+
* @param request GetEntityTokenRequest
24+
* @return Async Task will return GetEntityTokenResponse
25+
*/
26+
@SuppressWarnings("unchecked")
27+
public static FutureTask<PlayFabResult<GetEntityTokenResponse>> GetEntityTokenAsync(final GetEntityTokenRequest request) {
28+
return new FutureTask(new Callable<PlayFabResult<GetEntityTokenResponse>>() {
29+
public PlayFabResult<GetEntityTokenResponse> call() throws Exception {
30+
return privateGetEntityTokenAsync(request);
31+
}
32+
});
33+
}
34+
35+
/**
36+
* Method to exchange a legacy AuthenticationTicket or title SecretKey for an Entity Token or to refresh a still valid
37+
* Entity Token.
38+
* @param request GetEntityTokenRequest
39+
* @return GetEntityTokenResponse
40+
*/
41+
@SuppressWarnings("unchecked")
42+
public static PlayFabResult<GetEntityTokenResponse> GetEntityToken(final GetEntityTokenRequest request) {
43+
FutureTask<PlayFabResult<GetEntityTokenResponse>> task = new FutureTask(new Callable<PlayFabResult<GetEntityTokenResponse>>() {
44+
public PlayFabResult<GetEntityTokenResponse> call() throws Exception {
45+
return privateGetEntityTokenAsync(request);
46+
}
47+
});
48+
try {
49+
task.run();
50+
return task.get();
51+
} catch(Exception e) {
52+
return null;
53+
}
54+
}
55+
56+
/**
57+
* Method to exchange a legacy AuthenticationTicket or title SecretKey for an Entity Token or to refresh a still valid
58+
* Entity Token.
59+
*/
60+
@SuppressWarnings("unchecked")
61+
private static PlayFabResult<GetEntityTokenResponse> privateGetEntityTokenAsync(final GetEntityTokenRequest request) throws Exception {
62+
String authKey = null, authValue = null;
63+
if (PlayFabSettings.EntityToken != null) { authKey = "X-EntityToken"; authValue = PlayFabSettings.EntityToken; }
64+
else if (PlayFabSettings.ClientSessionTicket != null) { authKey = "X-Authorization"; authValue = PlayFabSettings.ClientSessionTicket; }
65+
else if (PlayFabSettings.DeveloperSecretKey != null) { authKey = "X-SecretKey"; authValue = PlayFabSettings.DeveloperSecretKey; }
66+
67+
FutureTask<Object> task = PlayFabHTTP.doPost(PlayFabSettings.GetURL() + "/Authentication/GetEntityToken", request, authKey, authValue);
68+
task.run();
69+
Object httpResult = task.get();
70+
if (httpResult instanceof PlayFabError) {
71+
PlayFabError error = (PlayFabError)httpResult;
72+
if (PlayFabSettings.GlobalErrorHandler != null)
73+
PlayFabSettings.GlobalErrorHandler.callback(error);
74+
PlayFabResult result = new PlayFabResult<GetEntityTokenResponse>();
75+
result.Error = error;
76+
return result;
77+
}
78+
String resultRawJson = (String) httpResult;
79+
80+
PlayFabJsonSuccess<GetEntityTokenResponse> resultData = gson.fromJson(resultRawJson, new TypeToken<PlayFabJsonSuccess<GetEntityTokenResponse>>(){}.getType());
81+
GetEntityTokenResponse result = resultData.data;
82+
PlayFabSettings.EntityToken = result.EntityToken != null ? result.EntityToken : PlayFabSettings.EntityToken;
83+
84+
PlayFabResult<GetEntityTokenResponse> pfResult = new PlayFabResult<GetEntityTokenResponse>();
85+
pfResult.Result = result;
86+
return pfResult;
87+
}
88+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.playfab;
2+
3+
import java.util.*;
4+
import com.playfab.PlayFabUtil.*;
5+
6+
public class PlayFabAuthenticationModels {
7+
8+
/** Entity identifier class that contains both the ID and type. */
9+
public static class EntityKey {
10+
/** Entity profile ID. */
11+
public String Id;
12+
/** Entity type. Optional to be used but one of EntityType or EntityTypeString must be set. */
13+
public EntityTypes Type;
14+
/** Entity type. Optional to be used but one of EntityType or EntityTypeString must be set. */
15+
public String TypeString;
16+
17+
}
18+
19+
public static enum EntityTypes {
20+
title,
21+
master_player_account,
22+
title_player_account,
23+
character,
24+
group,
25+
service
26+
}
27+
28+
public static class GetEntityTokenRequest {
29+
/** The entity to perform this action on. */
30+
public EntityKey Entity;
31+
32+
}
33+
34+
public static class GetEntityTokenResponse {
35+
/** The entity id and type. */
36+
public EntityKey Entity;
37+
/** The token used to set X-EntityToken for all entity based API calls. */
38+
public String EntityToken;
39+
/** The time the token will expire, if it is an expiring token, in UTC. */
40+
public Date TokenExpiration;
41+
42+
}
43+
44+
}

0 commit comments

Comments
 (0)