/// <summary> /// Callback for authentication success using the BrainCloudWrapper class. /// </summary> /// <param name="json">The returned json</param> /// <param name="cbObject">The returned callback object</param> protected virtual void AuthSuccessCallback(string json, object cbObject) { // grab the profileId and save it in PlayerPrefs Dictionary <string, object> jsonMessage = (Dictionary <string, object>)JsonReader.Deserialize(json); Dictionary <string, object> jsonData = (Dictionary <string, object>)jsonMessage["data"]; string profileId = ""; if (jsonData.ContainsKey("profileId")) { profileId = (string)jsonData["profileId"]; } if (profileId != "") { SetStoredProfileId(profileId); } if (cbObject != null) { WrapperAuthCallbackObject aco = (WrapperAuthCallbackObject)cbObject; if (aco._successCallback != null) { aco._successCallback(json, aco._cbObject); } } #if UNITY_EDITOR BrainCloudUnity.BrainCloudPlugin.ResponseEvent.OnAuthenticateSuccess(json); #endif }
/// <summary> /// Callback for authentication failure using the BrainCloudWrapper class. /// </summary> /// <param name="statusCode">The status code</param> /// <param name="reasonCode">The reason code</param> /// <param name="errorJson">The error json</param> /// <param name="cbObject">The returned callback object</param> protected virtual void AuthFailureCallback(int statusCode, int reasonCode, string errorJson, object cbObject) { if (cbObject != null) { WrapperAuthCallbackObject aco = (WrapperAuthCallbackObject)cbObject; if (aco._failureCallback != null) { aco._failureCallback(statusCode, reasonCode, errorJson, aco._cbObject); } } }
/// <summary> /// Callback for authentication failure using the BrainCloudWrapper class. /// </summary> /// <param name="statusCode">The status code</param> /// <param name="reasonCode">The reason code</param> /// <param name="errorJson">The error json</param> /// <param name="cbObject">The returned callback object</param> protected virtual void AuthFailureCallback(int statusCode, int reasonCode, string errorJson, object cbObject) { if (cbObject != null) { WrapperAuthCallbackObject aco = (WrapperAuthCallbackObject)cbObject; if (aco._failureCallback != null) { aco._failureCallback(statusCode, reasonCode, errorJson, aco._cbObject); } } #if UNITY_EDITOR BrainCloudUnity.BrainCloudPlugin.ResponseEvent.OnAuthenticateFailed(string.Format("statusCode[{0}] reasonCode[{1}] errorJson[{2}]", statusCode, reasonCode, errorJson)); #endif }
/// <summary> /// Authenticate a user anonymously with brainCloud - used for apps that don't want to bother /// the user to login, or for users who are sensitive to their privacy /// /// Note that this method is special in that the anonymous id and profile id /// are persisted to the Unity player prefs cache if authentication is successful. /// Both pieces of information are required to successfully log into that account /// once the user has been created. Failure to store the profile id and anonymous id /// once the user has been created results in an inability to log into that account! /// For this reason, using other recoverable authentication methods (like email/password, Facebook) /// are encouraged. /// </summary> /// <remarks> /// Service Name - Authenticate /// Service Operation - Authenticate /// </remarks> /// <param name="success"> /// The method to call in event of successful login /// </param> /// <param name="failure"> /// The method to call in the event of an error during authentication /// </param> /// <param name="cbObject"> /// The user supplied callback object /// </param> public void AuthenticateAnonymous( SuccessCallback success = null, FailureCallback failure = null, object cbObject = null) { WrapperAuthCallbackObject aco = new WrapperAuthCallbackObject(); aco._successCallback = success; aco._failureCallback = failure; aco._cbObject = cbObject; InitializeIdentity(true); Client.AuthenticationService.AuthenticateAnonymous( true, AuthSuccessCallback, AuthFailureCallback, aco); }
/// <summary> /// Authenticate the user using their Game Center id /// </summary> /// <remarks> /// Service Name - Authenticate /// Service Operation - Authenticate /// </remarks> /// <param name="gameCenterId"> /// The user's game center id (use the playerID property from the local GKPlayer object) /// </param> /// <param name="forceCreate"> /// Should a new profile be created for this user if the account does not exist? /// </param> /// <param name="success"> /// The method to call in event of successful login /// </param> /// <param name="failure"> /// The method to call in the event of an error during authentication /// </param> /// <param name="cbObject"> /// The user supplied callback object /// </param> public void AuthenticateGameCenter( string gameCenterId, bool forceCreate, SuccessCallback success = null, FailureCallback failure = null, object cbObject = null) { WrapperAuthCallbackObject aco = new WrapperAuthCallbackObject(); aco._successCallback = success; aco._failureCallback = failure; aco._cbObject = cbObject; InitializeIdentity(); Client.AuthenticationService.AuthenticateGameCenter( gameCenterId, forceCreate, AuthSuccessCallback, AuthFailureCallback, aco); }
/// <summary> /// Authenticate the user using a userid and password (without any validation on the userid). /// Similar to AuthenticateEmailPassword - except that that method has additional features to /// allow for e-mail validation, password resets, etc. /// </summary> /// <remarks> /// Service Name - Authenticate /// Service Operation - Authenticate /// </remarks> /// <param name="email"> /// The e-mail address of the user /// </param> /// <param name="password"> /// The password of the user /// </param> /// <param name="forceCreate"> /// Should a new profile be created for this user if the account does not exist? /// </param> /// <param name="success"> /// The method to call in event of successful login /// </param> /// <param name="failure"> /// The method to call in the event of an error during authentication /// </param> /// <param name="cbObject"> /// The user supplied callback object /// </param> public void AuthenticateUniversal( string username, string password, bool forceCreate, SuccessCallback success = null, FailureCallback failure = null, object cbObject = null) { WrapperAuthCallbackObject aco = new WrapperAuthCallbackObject(); aco._successCallback = success; aco._failureCallback = failure; aco._cbObject = cbObject; InitializeIdentity(); Client.AuthenticationService.AuthenticateUniversal( username, password, forceCreate, AuthSuccessCallback, AuthFailureCallback, aco); }
/// <summary> /// Authenticate the user using a steam userid and session ticket (without any validation on the userid). /// </summary> /// <remarks> /// Service Name - Authenticate /// Service Operation - Authenticate /// </remarks> /// <param name="userid"> /// String representation of 64 bit steam id /// </param> /// <param name="sessionticket"> /// The session ticket of the user (hex encoded) /// </param> /// <param name="forceCreate"> /// Should a new profile be created for this user if the account does not exist? /// </param> /// <param name="success"> /// The method to call in event of successful login /// </param> /// <param name="failure"> /// The method to call in the event of an error during authentication /// </param> /// <param name="cbObject"> /// The user supplied callback object /// </param> public void AuthenticateSteam( string userid, string sessionticket, bool forceCreate, SuccessCallback success = null, FailureCallback failure = null, object cbObject = null) { WrapperAuthCallbackObject aco = new WrapperAuthCallbackObject(); aco._successCallback = success; aco._failureCallback = failure; aco._cbObject = cbObject; InitializeIdentity(); Client.AuthenticationService.AuthenticateSteam( userid, sessionticket, forceCreate, AuthSuccessCallback, AuthFailureCallback, aco); }
/// <summary> /// Authenticate the user with brainCloud using their Facebook Credentials /// </summary> /// <remarks> /// Service Name - Authenticate /// Service Operation - Authenticate /// </remarks> /// <param name="externalId"> /// The facebook id of the user /// </param> /// <param name="authenticationToken"> /// The validated token from the Facebook SDK (that will be further /// validated when sent to the bC service) /// </param> /// <param name="forceCreate"> /// Should a new profile be created for this user if the account does not exist? /// </param> /// <param name="success"> /// The method to call in event of successful login /// </param> /// <param name="failure"> /// The method to call in the event of an error during authentication /// </param> /// <param name="cbObject"> /// The user supplied callback object /// </param> public void AuthenticateFacebook( string fbUserId, string fbAuthToken, bool forceCreate, SuccessCallback success = null, FailureCallback failure = null, object cbObject = null) { WrapperAuthCallbackObject aco = new WrapperAuthCallbackObject(); aco._successCallback = success; aco._failureCallback = failure; aco._cbObject = cbObject; InitializeIdentity(); _client.AuthenticationService.AuthenticateFacebook( fbUserId, fbAuthToken, forceCreate, AuthSuccessCallback, AuthFailureCallback, aco); }
/// <summary> /// Authenticate the user via cloud code (which in turn validates the supplied credentials against an external system). /// This allows the developer to extend brainCloud authentication to support other backend authentication systems. /// </summary> /// <remarks> /// Service Name - Authenticate /// Service Operation - Authenticate /// </remarks> /// <param name="userid"> /// The user id /// </param> /// <param name="token"> /// The user token (password etc) /// </param> /// /// <param name="externalAuthName"> /// The name of the cloud script to call for external authentication /// </param> /// <param name="forceCreate"> /// Should a new profile be created for this user if the account does not exist? /// </param> /// <param name="success"> /// The method to call in event of successful login /// </param> /// <param name="failure"> /// The method to call in the event of an error during authentication /// </param> /// <param name="cbObject"> /// The user supplied callback object /// </param> public void AuthenticateExternal( string userid, string token, string externalAuthName, bool forceCreate, SuccessCallback success = null, FailureCallback failure = null, object cbObject = null) { WrapperAuthCallbackObject aco = new WrapperAuthCallbackObject(); aco._successCallback = success; aco._failureCallback = failure; aco._cbObject = cbObject; InitializeIdentity(); Client.AuthenticationService.AuthenticateExternal( userid, token, externalAuthName, forceCreate, AuthSuccessCallback, AuthFailureCallback, aco); }
/// <summary> /// Callback for authentication success using the BrainCloudWrapper class. /// </summary> /// <param name="json">The returned json</param> /// <param name="cbObject">The returned callback object</param> protected virtual void AuthSuccessCallback(string json, object cbObject) { // grab the profileId and save it in PlayerPrefs Dictionary <string, object> jsonMessage = (Dictionary <string, object>)JsonReader.Deserialize(json); Dictionary <string, object> jsonData = (Dictionary <string, object>)jsonMessage["data"]; string profileId = ""; if (jsonData.ContainsKey("profileId")) { profileId = (string)jsonData["profileId"]; } if (profileId != "") { SetStoredProfileId(profileId); } if (cbObject != null) { WrapperAuthCallbackObject aco = (WrapperAuthCallbackObject)cbObject; if (aco._successCallback != null) { aco._successCallback(json, aco._cbObject); } } }