You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
6.2 KiB
C#
122 lines
6.2 KiB
C#
#if !DISABLE_PLAYFABENTITY_API
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using PlayFab.AuthenticationModels;
|
|
using PlayFab.Internal;
|
|
using PlayFab.SharedModels;
|
|
|
|
namespace PlayFab
|
|
{
|
|
/// <summary>
|
|
/// 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. The
|
|
/// game_server API is designed to create uniquely identifiable game_server entities. The game_server Entity token can be
|
|
/// used to call Matchmaking Lobby and Pubsub for server scenarios.
|
|
/// </summary>
|
|
public class PlayFabAuthenticationInstanceAPI : IPlayFabInstanceApi
|
|
{
|
|
public readonly PlayFabApiSettings apiSettings = null;
|
|
public readonly PlayFabAuthenticationContext authenticationContext = null;
|
|
|
|
public PlayFabAuthenticationInstanceAPI()
|
|
{
|
|
authenticationContext = new PlayFabAuthenticationContext();
|
|
}
|
|
|
|
public PlayFabAuthenticationInstanceAPI(PlayFabApiSettings settings)
|
|
{
|
|
apiSettings = settings;
|
|
authenticationContext = new PlayFabAuthenticationContext();
|
|
}
|
|
|
|
public PlayFabAuthenticationInstanceAPI(PlayFabAuthenticationContext context)
|
|
{
|
|
authenticationContext = context ?? new PlayFabAuthenticationContext();
|
|
}
|
|
|
|
public PlayFabAuthenticationInstanceAPI(PlayFabApiSettings settings, PlayFabAuthenticationContext context)
|
|
{
|
|
apiSettings = settings;
|
|
authenticationContext = context ?? new PlayFabAuthenticationContext();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify entity login.
|
|
/// </summary>
|
|
public bool IsEntityLoggedIn()
|
|
{
|
|
return authenticationContext == null ? false : authenticationContext.IsEntityLoggedIn();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clear the Client SessionToken which allows this Client to call API calls requiring login.
|
|
/// A new/fresh login will be required after calling this.
|
|
/// </summary>
|
|
public void ForgetAllCredentials()
|
|
{
|
|
if (authenticationContext != null)
|
|
{
|
|
authenticationContext.ForgetAllCredentials();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a game_server entity token and return a new or existing game_server entity.
|
|
/// </summary>
|
|
public void AuthenticateGameServerWithCustomId(AuthenticateCustomIdRequest request, Action<AuthenticateCustomIdResult> resultCallback, Action<PlayFabError> errorCallback, object customData = null, Dictionary<string, string> extraHeaders = null)
|
|
{
|
|
var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext;
|
|
var callSettings = apiSettings ?? PlayFabSettings.staticSettings;
|
|
if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method");
|
|
PlayFabHttp.MakeApiCall("/GameServerIdentity/AuthenticateGameServerWithCustomId", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete a game_server entity.
|
|
/// </summary>
|
|
public void Delete(DeleteRequest request, Action<EmptyResponse> resultCallback, Action<PlayFabError> errorCallback, object customData = null, Dictionary<string, string> extraHeaders = null)
|
|
{
|
|
var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext;
|
|
var callSettings = apiSettings ?? PlayFabSettings.staticSettings;
|
|
if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method");
|
|
PlayFabHttp.MakeApiCall("/GameServerIdentity/Delete", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method to exchange a legacy AuthenticationTicket or title SecretKey for an Entity Token or to refresh a still valid
|
|
/// Entity Token.
|
|
/// </summary>
|
|
public void GetEntityToken(GetEntityTokenRequest request, Action<GetEntityTokenResponse> resultCallback, Action<PlayFabError> errorCallback, object customData = null, Dictionary<string, string> extraHeaders = null)
|
|
{
|
|
var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext;
|
|
var callSettings = apiSettings ?? PlayFabSettings.staticSettings;
|
|
AuthType authType = AuthType.None;
|
|
#if !DISABLE_PLAYFABCLIENT_API
|
|
if (context.IsClientLoggedIn()) { authType = AuthType.LoginSession; }
|
|
#endif
|
|
#if ENABLE_PLAYFABSERVER_API || ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFAB_SECRETKEY
|
|
if (callSettings.DeveloperSecretKey != null) { authType = AuthType.DevSecretKey; }
|
|
#endif
|
|
#if !DISABLE_PLAYFABENTITY_API
|
|
if (context.IsEntityLoggedIn()) { authType = AuthType.EntityToken; }
|
|
#endif
|
|
PlayFabHttp.MakeApiCall("/Authentication/GetEntityToken", request, authType, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method for a server to validate a client provided EntityToken. Only callable by the title entity.
|
|
/// </summary>
|
|
public void ValidateEntityToken(ValidateEntityTokenRequest request, Action<ValidateEntityTokenResponse> resultCallback, Action<PlayFabError> errorCallback, object customData = null, Dictionary<string, string> extraHeaders = null)
|
|
{
|
|
var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext;
|
|
var callSettings = apiSettings ?? PlayFabSettings.staticSettings;
|
|
if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method");
|
|
PlayFabHttp.MakeApiCall("/Authentication/ValidateEntityToken", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
#endif
|