Introduction
What is brainCloud?
brainCloud is a ready-made back-end platform for the development of feature-rich games, apps and things. brainCloud provides the features you need – along with comprehensive tools to support your team during development, testing and user support.
brainCloud consists of:
- Cloud Service – an advanced, Software-as-a-Service (SaaS) back-end
- Client Libraries – local client libraries (SDKs)
- Design Portal – a portal that allows you to design and debug your apps
SDK libraries
There are custom brainCloud libraries for several languages including:
- Unity / C#
- C++
- Objective-C / Swift
- Java
- JavaScript
Engine Support
brainCloud supports the most popular gaming engines, including:
- Unity – brainCloud provides C# libraries, examples and tutorials for integration with Unity
- Unreal – We have full support for Unreal Engine 4 including Blueprints and C++
- Cocos2d-x – Cocos is supported natively using our C++ libraries
BrainCloudWrapper
// Unity
//Note: Ensure of have selected your app using the brainCloud Unity Plugin
using UnityEngine;
public class BCConfig : MonoBehaviour {
private BrainCloudWrapper _bc;
public BrainCloudWrapper GetBrainCloud()
{
return _bc;
}
void Awake ()
{
DontDestroyOnLoad(gameObject);
_bc = gameObject.AddComponent<BrainCloudWrapper>();
_bc.WrapperName = gameObject.name; // Optional: Set a wrapper name
_bc.Init(); // Init data is taken from the brainCloud Unity Plugin
}
}
// C#
_bc = new BrainCloudWrapper("_mainWrapper");
_bc = new BrainCloudWrapper("_mainWrapper");
_bc = new BrainCloudWrapper("_mainWrapper");
_bc = [[BrainCloudWrapper alloc] init: @"_mainWrapper"]
_bc = new BrainCloudWrapper("_mainWrapper");
The BrainCloudWrapper class provides an easier way for developers to handle user authentication when they are getting started with the authentication system. This includes persisting authentication data between application runs.
By using the wrapper authentication methods, the anonymous and profile IDs will be automatically persisted upon successful authentication. When authenticating, any stored anonymous/profile IDs will be sent to the server. This strategy is useful when using Anonymous authentication.
Note - you should initialize the wrapper before using it. It will in turn initialize the brainCloud client for you - don't do both!
Method Parameters
Parameter | Description |
---|---|
wrapperName | Distincts saved wrapper data. Use when using more than one instance of brainCloud |
AuthenticateAnonymous
_bc->authenticateAnonymous(this);
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticateAnonymous(successCallback, failureCallback);
_bc.authenticateAnonymous();
[_bc authenticateAnonymous:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
_bc.authenticateAnonymous(result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
{
"status": 200,
"data": {
"vcPurchased": 0,
"xpCapped": false,
"experiencePoints": 230,
"sent_events": [
],
"playerSessionExpiry": 1200,
"playerName": "Jimmy",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"loginCount": 23,
"server_time": 1445545791711,
"experienceLevel": 0,
"entities": [
],
"incoming_events": [
],
"currency": {
"gold": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0
}
},
"statistics": {
"deaths": 0,
"kills": 0
},
"abTestingId": 78,
"id": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"sessionId": "bg6qf38p2btl0o825s99385nd1",
"profileId": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"newUser": "false"
}
}
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.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Status Codes
public void FailureCallback(int statusCode, int reasonCode, string statusMessage, object cbObject) {
switch (reasonCode) {
case ReasonCodes.MISSING_IDENTITY_ERROR: { // Identity does not match any profile
// Reset Profile ID and re-authenticate
_bc.ResetStoredProfileId();
_bc.AuthenticateAnonymous();
break;
}
case ReasonCodes.SWITCHING_PROFILES: { // Identity belongs to a different profile
// Reset Profile ID and Anonymous id, and then re-authenticate
_bc.ResetStoredProfileId();
_bc.ResetStoredAnonymousId();
_bc.AuthenticateAnonymous();
break;
}
default: { // Uncaught reasonCode // Uncaught reasonCode
// Log the error for debugging later
// ...
break;
}
}
}
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | Both an anonymousId and profileId were provided for authentication - but the anonymousId doesn't exist on the server. The profileId may or may not exist. It is possible that the user account was deleted via the Design Portal. The proper recourse is to reset the stored profile id, and re-authenticate. [There is no need to delete the anonymousId since it doesn't exist on the server anyway.] |
40207 | SWITCHING_PROFILES | This means that the anonymousId provided does point to a profile, but not the same one that was saved in the client. This fails the anonymous security check. For any other authentication type, this might indicate that the user wants to switch accounts (thus the name of the error constant). For anonymous, the only response is to reset both the stored anonymousId and profileId, and then re-authenticate. |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication |
AuthenticateEmailPassword
string email = "my_Email@getbraincloud.com";
string password = "MyP@ssW0rd!";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticateEmailPassword(
email, password, forceCreate, successCallback, failureCallback);
const char* email = "my_Email@getbraincloud.com";
const char* password = "MyP@ssW0rd!";
bool forceCreate = true;
_bc->authenticateEmailPassword(email, password, forceCreate, this);
NSString* email = @"my_Email@getbraincloud.com";
NSString* password = @"MyP@ssW0rd!";
bool forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc authenticateEmailPassword:email
password:password
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String email = "my_Email@getbraincloud.com";
String password = "MyP@ssW0rd!";
boolean forceCreate = true;
_bc.authenticateEmailPassword(
email,
password,
forceCreate,
this);
var email = "my_Email@getbraincloud.com";
var password = "MyP@ssW0rd!";
var forceCreate = true;
_bc.authenticateEmailPassword(email, password, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
{
"status": 200,
"data": {
"vcPurchased": 0,
"xpCapped": false,
"experiencePoints": 230,
"sent_events": [
],
"playerSessionExpiry": 1200,
"playerName": "Jimmy",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"loginCount": 23,
"server_time": 1445545791711,
"experienceLevel": 0,
"entities": [
],
"incoming_events": [
],
"currency": {
"gold": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0
}
},
"statistics": {
"deaths": 0,
"kills": 0
},
"abTestingId": 78,
"id": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"sessionId": "bg6qf38p2btl0o825s99385nd1",
"profileId": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"newUser": "false"
}
}
Authenticate the user with a custom Email and Password. Note that the client app is responsible for collecting (and storing) the e-mail and potentially password (for convenience) in the client data. For the greatest security, force the user to re-enter their password at each login (or at least give them that option).
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
The e-mail address of the user | |
password | The password of the user |
forceCreate | Should a new profile be created for this user if the account does not exist? |
public void FailureCallback(int statusCode, int reasonCode, string statusMessage, object cbObject) {
switch (reasonCode) {
case ReasonCodes.MISSING_IDENTITY_ERROR: { // Identity does not exist (and client has orphaned profileId)
// Reset profileId and re-authenticate
_bc.ResetStoredProfileId();
_bc.AuthenticateUniversal(userId, password, true);
break;
}
case ReasonCodes.SWITCHING_PROFILES: { // Identity belongs to a different profile
// [Optional] Prompt user to confirm that they wish to switch accounts?
// Reset profileId and re-authenticate
_bc.ResetStoredProfileId();
_bc.AuthenticateUniversal(userId, password, forceCreate);
break;
}
case ReasonCodes.MISSING_PROFILE_ERROR: { // Identity does not exist
// The account doesn't exist - create it now.
_bc.AuthenticateUniversal(userId, password, true);
break;
}
case ReasonCodes.TOKEN_DOES_NOT_MATCH_USER: { // Wrong password
// Display a dialog telling the user that the password provided was invalid,
// and invite them to re-enter the password.
// ...
break;
}
default: { // Uncaught reasonCode
// Log the error for debugging later
// ...
break;
}
}
}
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [and unrelated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials don't match (i.e. incorrect password). |
AuthenticateExternal
string userId = "externalId";
string token = "externalTokenOrPassword";
string externalAuthName = "nameOfExternalAuthService";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticateExternal(
userId, token, externalAuthName, forceCreate,
successCallback, failureCallback);
const char* userId = "externalId";
const char* token = "externalTokenOrPassword";
const char* externalAuthName = "nameOfExternalAuthService";
_bc->authenticateExternal(
userId,
token,
externalAuthName,
true,
this);
NSString* authId = @"1234";
NSString* authToken = @"1234-1234-1234-1234";
NSString* externalAuthName = @"externalSystem";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc authenticateExternal:authId
authenticationToken:authToken
externalAuthenticationName:externalAuthName
forceCreate:true
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String userId = "externalId";
String token = "externalTokenOrPassword";
String externalAuthName = "nameOfExternalAuthService";
_bc.authenticateExternal(
userId,
token,
externalAuthName,
true,
this);
var userId = "externalId";
var token = "externalTokenOrPassword";
var externalAuthName = "nameOfExternalAuthService";
var forceCreate = true;
_bc.authenticateExternal(userId, token, externalAuthName, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
{
"status": 200,
"data": {
"vcPurchased": 0,
"xpCapped": false,
"experiencePoints": 230,
"sent_events": [
],
"playerSessionExpiry": 1200,
"playerName": "Jimmy",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"loginCount": 23,
"server_time": 1445545791711,
"experienceLevel": 0,
"entities": [
],
"incoming_events": [
],
"currency": {
"gold": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0
}
},
"statistics": {
"deaths": 0,
"kills": 0
},
"abTestingId": 78,
"id": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"sessionId": "bg6qf38p2btl0o825s99385nd1",
"profileId": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"newUser": "false"
}
}
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.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
userId | The userId |
token | The user token (password etc) |
externalAuthName | The name of the custom authentication type (linked to a cloud script that performs authentication). Configured via the Design | Authentication | External page of the Design Portal. |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials don't match (according to the 3rd party system). May also indicate an issue with the external authentication script. |
AuthenticateFacebook
string facebookId = "userFacebookId";
string facebookToken = "tokenFromFacebook";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticateFacebook(
facebookId, facebookToken, forceCreate,
successCallback, failureCallback);
const char* facebookId = "userFacebookId";
const char* facebookToken = "tokenFromFacebook";
bool forceCreate = true;
_bc->authenticateFacebook(
facebookId,
facebookToken,
forceCreate,
this);
NSString* facebookId = @"userFacebookId";
NSString* facebookToken = @"tokenFromFacebook";
bool forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc authenticateExternal:facebookId
authenticationToken:facebookToken
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String facebookId = "userFacebookId";
String facebookToken = "tokenFromFacebook";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.authenticateFacebook(facebookId, facebookToken, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var facebookId = "userFacebookId";
var token = "tokenFromFacebook";
var forceCreate = true;
_bc.authenticateFacebook(facebookId, token, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
{
"status": 200,
"data": {
"vcPurchased": 0,
"xpCapped": false,
"experiencePoints": 230,
"sent_events": [
],
"playerSessionExpiry": 1200,
"playerName": "Jimmy",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"loginCount": 23,
"server_time": 1445545791711,
"experienceLevel": 0,
"entities": [
],
"incoming_events": [
],
"currency": {
"gold": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0
}
},
"statistics": {
"deaths": 0,
"kills": 0
},
"abTestingId": 78,
"id": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"sessionId": "bg6qf38p2btl0o825s99385nd1",
"profileId": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"newUser": "false"
}
}
Authenticate the user with brainCloud using their Facebook Credentials.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
facebookId | The Facebook ID of the user |
facebookToken | The validated token from the Facebook SDK |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials are invalid (i.e. bad Facebook id / token). May also indicate that Facebook integration is not properly configured. |
AuthenticateGameCenter
string gameCenterId = "userGameCenterId";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticateGameCenter(
gameCenterId, forceCreate,
successCallback, failureCallback);
const char* gameCenterId = "userGameCenterId";
bool forceCreate = true;
_bc->authenticateGameCenter(
gameCenterId,
forceCreate,
this);
NSString* gameCenterID = @"userGameCenterId";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc authenticateGameCenter:gameCenterID
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
// N/A
var gameCenterId = "userGameCenterId";
var forceCreate = true;
_bc.authenticateGameCenter(gameCenterId, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
{
"status": 200,
"data": {
"vcPurchased": 0,
"xpCapped": false,
"experiencePoints": 230,
"sent_events": [
],
"playerSessionExpiry": 1200,
"playerName": "Jimmy",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"loginCount": 23,
"server_time": 1445545791711,
"experienceLevel": 0,
"entities": [
],
"incoming_events": [
],
"currency": {
"gold": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0
}
},
"statistics": {
"deaths": 0,
"kills": 0
},
"abTestingId": 78,
"id": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"sessionId": "bg6qf38p2btl0o825s99385nd1",
"profileId": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"newUser": "false"
}
}
Authenticate the user using their Game Center ID.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
gameCenterId | The player's game center ID (use the playerID property from the local GKPlayer object) |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the design portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials are invalid (i.e. bad gameCenterId ) |
AuthenticateGoogle
string googleId = "g123456789";
string googleToken = "authTokenFromGoogle";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticateGoogle(
googleId, googleToken, forceCreate,
successCallback, failureCallback);
const char* googleId = "g123456789";
const char* googleToken = "authTokenFromGoogle";
bool forceCreate = true;
_bc->authenticateGoogle(
googleId, googleToken, forceCreate, this);
NSString* googleId = @"g123456789";
NSString* googleToken = @"authTokenFromGoogle";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc authenticateGoogle:googleId
token:googleToken
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String googleId = "g123456789";
String googleToken = "authTokenFromGoogle";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.authenticateGoogle(
googleId, googleToken, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var googleId = "g123456789";
var googleToken = "authTokenFromGoogle";
var forceCreate = true;
_bc.authenticateGoogle(googleId, googleToken, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
{
"status": 200,
"data": {
"vcPurchased": 0,
"xpCapped": false,
"experiencePoints": 230,
"sent_events": [
],
"playerSessionExpiry": 1200,
"playerName": "Jimmy",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"loginCount": 23,
"server_time": 1445545791711,
"experienceLevel": 0,
"entities": [
],
"incoming_events": [
],
"currency": {
"gold": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0
}
},
"statistics": {
"deaths": 0,
"kills": 0
},
"abTestingId": 78,
"id": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"sessionId": "bg6qf38p2btl0o825s99385nd1",
"profileId": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"newUser": "false"
}
}
Authenticate the user using a google user ID (gXXX) and google authentication token.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
googleId | String representation of google userid (gXXX) |
googleToken | The authentication token derived via the google apis. |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials are invalid (i.e. googleId and googleToken are invalid). May also indicate that Google Integration is not properly configured. |
AuthenticateSteam
string steamId = "userSteamId";
string sessionTicket = "sessionTicketFromSteam";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticateSteam(
steamId, tisessionTicketcket, forceCreate,
successCallback, failureCallback);
const char* steamId = "userSteamId";
const char* sessionTicket = "sessionTicketFromSteam";
bool forceCreate = true;
_bc->authenticateSteam(
steamId, sessionTicket, forceCreate, this);
NSString* userID = @"userSteamId";
NSString* sessionticket = @"sessionTicketFromSteam";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc authenticateSteam:userID
sessionTicket:sessionticket
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
Steam steamId = "userSteamId";
Steam sessionTicket = "sessionTicketFromSteam";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.authenticateSteam(
steamId, sessionTicket, forceCreate, this);
var steamId = "userSteamId";
var sessionTicket = "sessionTicketFromSteam";
var forceCreate = true;
_bc.authenticateSteam(steamId, sessionTicket, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
{
"status": 200,
"data": {
"vcPurchased": 0,
"xpCapped": false,
"experiencePoints": 230,
"sent_events": [
],
"playerSessionExpiry": 1200,
"playerName": "Jimmy",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"loginCount": 23,
"server_time": 1445545791711,
"experienceLevel": 0,
"entities": [
],
"incoming_events": [
],
"currency": {
"gold": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0
}
},
"statistics": {
"deaths": 0,
"kills": 0
},
"abTestingId": 78,
"id": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"sessionId": "bg6qf38p2btl0o825s99385nd1",
"profileId": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"newUser": "false"
}
}
Authenticate the user using a steam userId and session ticket (without any validation on the userId).
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
userId | String representation of 64 bit steam ID |
sessionTicket | The session ticket of the user (hex encoded) |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials are invalid (i.e. bad Steam userId and/or sessionTicket). May also indicate that Steam Integration is not properly configured. |
AuthenticateTwitter
string twitterId = "userTwitterId";
string token = "userAuthToken";
string secret = "secretFromTwitterApi";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticateTwitter(
twitterId, token, secret, forceCreate,
successCallback, failureCallback);
const char* twitterId = "userTwitterId";
const char* token = "userAuthToken";
const char* secret = "secretFromTwitterApi";
_bc->authenticateTwitter(
twitterId, token, secret, true, this);
NSString* twitterId = @"userTwitterId";
NSString* token = @"userAuthToken";
NSString* secret = @"secretFromTwitterApi";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc authenticateTwitter:userID
token:token
secret:secret
forceCreate:true
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String twitterId = "userTwitterId";
String token = "userAuthToken";
String secret = "secretFromTwitterApi";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.authenticateTwitter(
twitterId, token, secret, forceCreate, this);
var twitterId = "userTwitterId";
var token = "userAuthToken";
var secret = "secretFromTwitterApi";
var forceCreate = true;
_bc.authenticateTwitter(twitterId, token, secret, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
{
"status": 200,
"data": {
"vcPurchased": 0,
"xpCapped": false,
"experiencePoints": 230,
"sent_events": [
],
"playerSessionExpiry": 1200,
"playerName": "Jimmy",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"loginCount": 23,
"server_time": 1445545791711,
"experienceLevel": 0,
"entities": [
],
"incoming_events": [
],
"currency": {
"gold": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0
}
},
"statistics": {
"deaths": 0,
"kills": 0
},
"abTestingId": 78,
"id": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"sessionId": "bg6qf38p2btl0o825s99385nd1",
"profileId": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"newUser": "false"
}
}
Authenticate the user using a Twitter user ID, authentication token, and secret from Twitter.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
userId | String representation of Twitter user ID |
token | The authentication token derived via the Twitter APIs |
secret | The secret given when attempting to link with Twitter |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials are invalid (i.e. bad Twitter userId / token / secret). May also indicate that Twitter integration is not properly configured. |
AuthenticateUniversal
string userId = "MyUserName_007";
string password = "MyP@ssW0rd!";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticateUniversal(userId, password, forceCreate, successCallback, failureCallback);
const char* userId = "MyUserName_007";
const char* password = "MyP@ssW0rd!";
bool forceCreate = true;
_bc->authenticateUniversal(userId, password, forceCreate, this);
NSString* userId = @"MyUserName_007";
NSString* password = @"MyP@ssW0rd!";
bool forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc authenticateUniversal:userId
password:password
forceCreate:forCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String userId = "MyUserName_007";
String password = "MyP@ssW0rd!";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.authenticateUniversal(userId, password, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var userId = "MyUserName_007";
var password = "MyP@ssW0rd!";
var forceCreate = true;
_bc.authenticateUniversal(userId, password, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
{
"status": 200,
"data": {
"vcPurchased": 0,
"xpCapped": false,
"experiencePoints": 230,
"sent_events": [
],
"playerSessionExpiry": 1200,
"playerName": "Jimmy",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"loginCount": 23,
"server_time": 1445545791711,
"experienceLevel": 0,
"entities": [
],
"incoming_events": [
],
"currency": {
"gold": {
"purchased": 0,
"balance": 0,
"consumed": 0,
"awarded": 0
}
},
"statistics": {
"deaths": 0,
"kills": 0
},
"abTestingId": 78,
"id": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"sessionId": "bg6qf38p2btl0o825s99385nd1",
"profileId": "47037fc9-ca7b-4f61-a71f-e5a37b0e8a03",
"newUser": "false"
}
}
Universal authentication allows the developer to pass in any user/password string combination. As with all authentication methods, if the create new profile flag is specified as false, the authentication will fail if the user/password combination does not match a user in the database.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
userId | The user's ID. |
password | The password of the user. |
forceCreate | Should a new profile be created for this user if the account does not exist? |
public void FailureCallback(int statusCode, int reasonCode, string statusMessage, object cbObject) {
switch (reasonCode) {
case ReasonCodes.MISSING_IDENTITY_ERROR: { // Identity does not exist (and client has orphaned profileId)
// Reset profileId and re-authenticate
_bc.ResetStoredProfileId();
_bc.AuthenticateUniversal(userId, password, true);
break;
}
case ReasonCodes.SWITCHING_PROFILES: { // Identity belongs to a different profile
// [Optional] Prompt user to confirm that they wish to switch accounts?
// Reset profileId and re-authenticate
_bc.ResetStoredProfileId();
_bc.AuthenticateUniversal(userId, password, forceCreate);
break;
}
case ReasonCodes.MISSING_PROFILE_ERROR: { // Identity does not exist
// The account doesn't exist - create it now.
_bc.AuthenticateUniversal(userId, password, true);
break;
}
case ReasonCodes.TOKEN_DOES_NOT_MATCH_USER: { // Wrong password
// Display a dialog telling the user that the password provided was invalid,
// and invite them to re-enter the password.
// ...
break;
}
default: { // Uncaught reasonCode
// Log the error for debugging later
// ...
break;
}
}
}
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [and unrelated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials don't match (i.e. incorrect password). |
GetAlwaysAllowProfileSwitch
bool allowSwitch = _bc.GetAlwaysAllowProfileSwitch();
bool alwaysAllow = _bc.AlwaysAllowProfileSwitch;
_bc.AlwaysAllowProfileSwitch = false; // Disables profile switches.
bool allowSwitch = _bc.getAlwaysAllowProfileSwitch();
BOOL allowSwitch = _bc.alwaysAllowProfileSwitch;
var allowSwitch = _bc.getAlwaysAllowProfileSwitch();
For non-anonymous authentication methods, a profile ID will be passed in when this value is set to false. This will generate an error on the server if the profile ID passed in does not match the profile associated with the authentication credentials.
By default, this value is true.
GetStoredAnonymousId
//Step 1: Create and initialize the brainCloud Wrapper
// http://getbraincloud.com/apidocs/apiref/#wrapper
//Step 2: Now, you can use GetStoredAnonymousId
string anonymousId = _bc.GetStoredAnonymousId();
std::string anonymousId = _bc->getStoredAnonymousId();
String id = _bc.getStoredAnonymousId();
NSString* anonymousId = [_bc getStoredAnonymousId];
var anonymousId = _bc.getStoredAnonymousId();
Returns the stored anonymous ID
GetStoredProfileId
//Step 1: Create and initialize the brainCloud Wrapper
// http://getbraincloud.com/apidocs/apiref/#wrapper
//Step 2: Now, you can call GetStoredProfileId
string profileId = _bc.GetStoredProfileId();
std::string profileId = _bc->getStoredProfileId();
String id = _bc.getStoredProfileId();
NSString* profileId = [_bc getStoredProfileId];
var profileId = _bc.getStoredProfileId();
Returns the stored profile ID
Initialize
// Unity
GameObject go = new GameObject();
_bc = go.AddComponent<BrainCloudWrapper>();
_bc.WrapperName = _wrapperName; // optionally set a wrapper-name
_bc.Init(); // extra data, such as: _appId, _secret and _appVersion, is taken from the brainCloud Unity Plugin.
DontDestroyOnLoad(go); // keep the brainCloud game object through scene changes
// C#
string serverUrl = "https://sharedprod.braincloudservers.com/dispatcherv2";
string secret = "1234-1234-1234-1234";
string appId = "123456";
string version = "1.0.0";
_bc.Init(serverUrl, secret, appId, version);
const char* serverUrl = "https://sharedprod.braincloudservers.com/dispatcherv2";
const char* secret = "1234-1234-1234-1234";
const char* appId = "123456";
const char* version = "1.0.0";
const char* company = "bitHeads";
const char* appName = "Awesome Game";
_bc->initialize(serverUrl, secret, appId, version, company, appName);
public void initialize(Context ctx, String appId, String secretKey, String version)
NSString* serverUrl = @"https://sharedprod.braincloudservers.com/dispatcherv2";
NSString* secret = @"1234-1234-1234-1234";
NSString* appId = @"123456";
NSString* appId = @"1.0.0";
NSString* company = @"bitHeads";
NSString* appName = @"Awesome Game";
[_bc initialize:serverUrl
secretKey:secret
appId:appId
version:version
companyName:company
appName:appName];
secret = "1234-1234-1234-1234";
appId = "123456";
_bc.initialize(appId, secret, "1.0.0");
Method initializes both BrainCloudWrapper
and BrainCloudClient
.
The parameters for this method vary by client (for example the Unity client takes none at all, as all data is pulled from the brainCloud editor menu data).
Method Parameters
Parameter | Description |
---|---|
serverURL | The URL to the brainCloud server |
secretKey | The secret key for your app |
appId | The app ID |
version | The app version |
companyName | Client dependent - The company name used in the keychain for storing anonymous and profile IDs. You are free to pick anything you want. |
appName | Client dependent - The app name used in the keychain for storing anonymous and profile IDs. You are free to pick anything you want. |
InitializeWithApps
// Unity
GameObject go = new GameObject();
_bc = go.AddComponent<BrainCloudWrapper>();
_bc.WrapperName = _wrapperName; // optionally set a wrapper-name
_bc.InitWithApps(); // extra data, such as: _appId, _secret and _appVersion, is taken from the brainCloud Unity Plugin.
DontDestroyOnLoad(go); // keep the brainCloud game object through scene changes
// C#
string serverUrl = "https://sharedprod.braincloudservers.com/dispatcherv2";
string secret = "86c24079-5299-4659-8159-5352700c3a63";
string appId = "11787";
string childSecret = "80704bc0-2903-4f94-bf1d-f4f9fdc2c4f2";
string childAppId = "11788";
Dictionary<string, string> secretMap = new Dictionary<string, string>();
secretMap.Add(appId, secret);
secretMap.Add(childAppId, childSecret);
string version = "1.0.0";
_bc = new BrainCloudWrapper();
_bc.InitWithApps(serverUrl, appId, secretMap, version);
const char* serverUrl = "https://sharedprod.braincloudservers.com/dispatcherv2";
std::string secret = "86c24079-5299-4659-8159-5352700c3a63";
std::string appId = "11787";
std::string childSecret = "80704bc0-2903-4f94-bf1d-f4f9fdc2c4f2";
std::string childAppId = "11788";
std::map<std::string, std::string> secretMap;
secretMap[appId] = secret;
secretMap[childAppId] = childSecret;
const char* version = "1.0.0";
const char* company = "MyCompany Inc.";
const char* appName = "MyAwesome App";
_bc->initializeWithApps(serverUrl, appId.c_str(), secretMap, version, company, appName);
NSString* serverUrl = @"https://sharedprod.braincloudservers.com/dispatcherv2";
NSString* secret = @"86c24079-5299-4659-8159-5352700c3a63";
NSString* appId = @"11787";
NSString* childSecret = @"80704bc0-2903-4f94-bf1d-f4f9fdc2c4f2";
NSString* childAppId = @"11788";
NSDictionary* secretMap = @{
appId : secret,
childAppId : childSecret,
};
NSString* version = @"1.0.0";
[_bc initializeWithApps:serverUrl
defaultAppId:appId
secretMap:secretMap
appVersion:version];
String serverUrl = "https://sharedprod.braincloudservers.com/dispatcherv2";
String secret = "86c24079-5299-4659-8159-5352700c3a63";
String appId = "11787";
String childSecret = "80704bc0-2903-4f94-bf1d-f4f9fdc2c4f2";
String childAppId = "11788";
Map<String, String> secretMap = new HashMap<String, String>();
secretMap.put(appId, secret);
secretMap.put(childAppId, childSecret);
String version = "1.0.0";
_bc.initializeWithApps(serverUrl, appId, secretMap, version);
var secret = "86c24079-5299-4659-8159-5352700c3a63";
var appId = "11787";
var childSecret = "80704bc0-2903-4f94-bf1d-f4f9fdc2c4f2";
var childAppId = "11788";
var secretMap = {};
secretMap[appId] = secret;
secretMap[childAppId] = childSecret;
var version = "1.0.0";
_bc.initializeWithApps(appId, secretMap, version);
Method initializes BrainCloudWrapper
and BrainCloudClient
with a map of appid->secretkey.
The parameters for this method vary by client (for example the Unity client takes none at all, as all data is pulled from the brainCloud editor menu data).
Method Parameters
Parameter | Description |
---|---|
serverURL | The URL to the brainCloud server |
appId | The default app ID |
secretMap | All app ids to secret keys used by this application |
version | The app version |
companyName | Client dependent - The company name used in the keychain for storing anonymous and profile IDs. You are free to pick anything you want. |
appName | Client dependent - The app name used in the keychain for storing anonymous and profile IDs. You are free to pick anything you want. |
Reconnect
//Step 1: Initialize the brainCloud Wrapper and Authenticate the user
// http://getbraincloud.com/apidocs/apiref/#wrapper
//Step 2: Now, you can call Reconnect
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.Reconnect(successCallback, failureCallback);
_bc->reconnect(this);
_bc.reconnect(this);
- (void)reconnect:(BCCompletionBlock)cb
errorCompletionBlock:(BCErrorCompletionBlock)ecb
cbObject:(BCCallbackObject)cbObject;
_bc.reconnect(callback);
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
Re-authenticates the user with brainCloud
ResetEmailPassword
NSString *emailAddress = @"email@email.com";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticateService] resetEmailPassword:emailAddress
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
const char *emailAddress = "email@email.com";
_bc->getAuthenticationService()->resetEmailPassword(emailAddress, this);
string emailAddress = "email@email.com";
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.Authenticate.ResetEmailPassword(emailAddress, successCallback, failureCallback);
String emailAddress = "email@email.com";
this; // implements IServerCallback
_bc.getAuthenticationService().resetEmailPassword(emailAddress, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var emailAddress = "email@email.com";
_bc.authenticate.resetEmailPassword(emailAddress, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": null
}
Sends a password reset email to the specified address.
Service | Operation |
---|---|
"authenticationV2" | "RESET_EMAIL_PASSWORD" |
Method Parameters
Parameter | Description |
---|---|
emailAddress | The email address to send the reset email to. |
ResetEmailPasswordAdvanced
NSString *emailAddress = @"email@email.com";
NSString *serviceParams = @"{\"templateId\":\"template-id-guid\",\"substitutions\":{\"aKey\":\"aValue\"},\"categories\":[\"category1\",\"category2\"]}";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticateService] resetEmailPasswordAdvanced:emailAddress
serviceParams:serviceParams
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
const char *emailAddress = "email@email.com";
const char *serviceParams = "{\"templateId\":\"template-id-guid\",\"substitutions\":{\"aKey\":\"aValue\"},\"categories\":[\"category1\",\"category2\"]}";
_bc->getAuthenticationService()->resetEmailPasswordAdvanced(emailAddress, serviceParams, this);
string emailAddress = "email@email.com";
string serviceParams = "{\"templateId\":\"template-id-guid\",\"substitutions\":{\"aKey\":\"aValue\"},\"categories\":[\"category1\",\"category2\"]}";
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.Authenticate.ResetEmailPasswordAdvanced(emailAddress, serviceParams, successCallback, failureCallback);
String emailAddress = "email@email.com";
String serviceParams = "{\"templateId\":\"template-id-guid\",\"substitutions\":{\"aKey\":\"aValue\"},\"categories\":[\"category1\",\"category2\"]}";
this; // implements IServerCallback
_bc.getAuthenticationService().resetEmailPasswordAdvanced(emailAddress, serviceParams, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var emailAddress = "email@email.com";
var serviceParams = {
"templateId": "template-id-guid",
"substitutions": {
"aKey": "aValue"
},
"categories": [
"category1",
"category2"
]
};
_bc.authenticate.resetEmailPasswordAdvanced(emailAddress, serviceParams, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": null
}
Advanced reset email password using templates
Service | Operation |
---|---|
"authenticationV2" | "RESET_EMAIL_PASSWORD_ADVANCED" |
Method Parameters
Parameter | Description |
---|---|
emailAddress | The email address to send the reset email to. |
serviceParams | Set of parameters dependant on the mail service configured. |
ResetStoredAnonymousId
//Step 1: Create and initialize the brainCloud Wrapper
// http://getbraincloud.com/apidocs/apiref/#wrapper
//Step 2: Now, you can call GetAlwaysAllowProfileSwitch
_bc.ResetStoredAnonymousId();
_bc->resetStoredAnonymousId();
_bc.resetStoredAnonymousId();
_bc.storedAnonymousId = @"";
_bc.resetStoredAnonymousId();
Resets the anonymous ID to empty string. When the anonymousId is empty a new one will be generated automatically on authentication.
ResetStoredProfileId
//Step 1: Create and initialize the brainCloud Wrapper
// http://getbraincloud.com/apidocs/apiref/#wrapper
//Step 2: Now, you can call GetAlwaysAllowProfileSwitch
_bc.ResetStoredProfileId();
_bc->resetStoredProfileId();
_bc.resetStoredProfileId();
_bc.storedProfileId = @"";
_bc.resetStoredProfileId();
Resets the profile ID to empty string.
RunCallbacks
//Step 1: Create and initialize the brainCloud Wrapper
// http://getbraincloud.com/apidocs/apiref/#wrapper
//Step 2: N/A. The brainCloud Wrapper Updates itself using Unity MonoBehavior Update
// However, if you are not using Unity or not using the BrainCloudWrapper as a GameObject, call Update in your own update loop
_bc.Update();
_bc->runCallbacks();
[_bc runCallbacks];
_bc.runCallbacks();
// N/A
Run callbacks, to be called once per frame from your main thread
SetAlwaysAllowProfileSwitch
_bc.SetAlwaysAllowProfileSwitch(false); // Default is true
_bc->setAlwaysAllowProfileSwitch(true);
_bc.setAlwaysAllowProfileSwitch(true);
_bc.alwaysAllowProfileSwitch = YES;
_bc.setAlwaysAllowProfileSwitch(true);
For non-anonymous authentication methods, a profile ID will be passed in when this value is set to false. This will generate an error on the server if the profile ID passed in does not match the profile associated with the authentication credentials.
By default, this value is true.
Method Parameters
Parameter | Description |
---|---|
alwaysAllow | Controls whether the profile ID is passed in with non-anonymous authentications. |
SetStoredAnonymousId
_bc.SetStoredAnonymousId("1234-1234-1234-1234");
_bc->setStoredAnonymousId("1234-1234-1234-1234");
// N/A
_bc.storedAnonymousId = @"1234-1234-1234-1234";
_bc.setStoredAnonymousId("1234-1234-1234-1234");
Sets the stored anonymous ID
Method Parameters
Parameter | Description |
---|---|
anonymousId | The anonymous ID to set |
SetStoredProfileId
_bc.SetStoredProfileId("1234-1234-1234-1234");
_bc->setStoredProfileId("1234-1234-1234-1234");
_bc.setStoredProfileId("1234-1234-1234-1234");
_bc.storedProfileId = @"1234-1234-1234-1234";
_bc.setStoredProfileId("1234-1234-1234-1234");
Sets the stored profile ID
Method Parameters
Parameter | Description |
---|---|
profileId | The profile ID to set |
SmartSwitchAuthenticateEmailPassword
string email = "my_Email@getbraincloud.com";
string password = "MyP@ssW0rd!";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.SmartSwitchAuthenticateEmail(
email, password, forceCreate, successCallback, failureCallback);
const char* email = "my_Email@getbraincloud.com";
const char* password = "MyP@ssW0rd!";
bool forceCreate = true;
_bc->smartSwitchAuthenticateEmailPassword(email, password, forceCreate, this);
NSString* email = @"my_Email@getbraincloud.com";
NSString* password = @"MyP@ssW0rd!";
bool forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc smartSwitchAuthenticateEmailPassword:email
password:password
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String email = "my_Email@getbraincloud.com";
String password = "MyP@ssW0rd!";
boolean forceCreate = true;
_bc.smartSwitchAuthenticateEmailPassword(
email,
password,
forceCreate,
this);
var email = "my_Email@getbraincloud.com";
var password = "MyP@ssW0rd!";
var forceCreate = true;
_bc.smartSwitchAuthenticateEmailPassword(email, password, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
Smart Switch Authenticate will logout of the current profile, and switch to the new authentication type. In event the current session was previously an anonymous account, the smart switch will delete that profile. Use this function to keep a clean designflow from anonymous to signed profiles
Authenticate the user with a custom Email and Password. Note that the client app is responsible for collecting and storing the e-mail and potentially password (for convenience) in the client data. For the greatest security, force the user to re-enter their password at each login (or at least give them that option).
Method Parameters
Parameter | Description |
---|---|
The e-mail address of the user | |
password | The password of the user |
forceCreate | Should a new profile be created for this user if the account does not exist? |
SmartSwitchAuthenticateExternal
string userId = "externalId";
string token = "externalTokenOrPassword";
string externalAuthName = "nameOfExternalAuthService";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.SmartSwitchAuthenticateExternal(
userId, token, externalAuthName, forceCreate,
successCallback, failureCallback);
const char* userId = "externalId";
const char* token = "externalTokenOrPassword";
const char* externalAuthName = "nameOfExternalAuthService";
_bc->smartSwitchAuthenticateExternal(
userId,
token,
externalAuthName,
true,
this);
NSString* authId = @"1234";
NSString* authToken = @"1234-1234-1234-1234";
NSString* externalAuthName = @"externalSystem";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc smartSwitchAuthenticateExternal:authId
authenticationToken:authToken
externalAuthenticationName:externalAuthName
forceCreate:true
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String userId = "externalId";
String token = "externalTokenOrPassword";
String externalAuthName = "nameOfExternalAuthService";
_bc.smartSwitchAuthenticateExternal(
userId,
token,
externalAuthName,
true,
this);
var userId = "externalId";
var token = "externalTokenOrPassword";
var externalAuthName = "nameOfExternalAuthService";
var forceCreate = true;
_bc.smartSwitchAuthenticateExternal(userId, token, externalAuthName, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
Smart Switch Authenticate will logout of the current profile, and switch to the new authentication type. In event the current session was previously an anonymous account, the smart switch will delete that profile. Use this function to keep a clean designflow from anonymous to signed profiles
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.
Method Parameters
Parameter | Description |
---|---|
userId | The userId |
token | The user token (password etc) |
externalAuthName | The name of the custom authentication type (linked to a cloud script that performs authentication). Configured via the Design | Authentication | External page of the Design Portal. |
forceCreate | Should a new profile be created for this user if the account does not exist? |
SmartSwitchAuthenticateFacebook
string facebookId = "userFacebookId";
string token = "tokenFromFacebook";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.SmartSwitchAuthenticateFacebook(
facebookId, token, forceCreate,
successCallback, failureCallback);
const char* facebookId = "userFacebookId";
const char* token = "tokenFromFacebook";
_bc->smartSwitchAuthenticateFacebook(
userId,
token,
true,
this);
NSString* externalID = @"userFacebookId";
NSString* authToken = @"tokenFromFacebook";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc smartSwitchAuthenticateExternal:externalID
authenticationToken:authToken
forceCreate:true
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
public void smartSwitchAuthenticateFacebook(String fbUserId, String fbAuthToken, boolean forceCreate, IAuthenticationServiceCallback callback)
var facebookId = "userFacebookId";
var token = "tokenFromFacebook";
var forceCreate = true;
_bc.smartSwitchAuthenticateFacebook(facebookId, token, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
Smart Switch Authenticate will logout of the current profile, and switch to the new authentication type. In event the current session was previously an anonymous account, the smart switch will delete that profile. Use this function to keep a clean designflow from anonymous to signed profiles
Authenticate the user with brainCloud using their Facebook Credentials
Method Parameters
Parameter | Description |
---|---|
userId | The userId |
facebookId | The Facebook ID of the user |
facebookToken | The validated token from the Facebook SDK |
forceCreate | Should a new profile be created for this user if the account does not exist? |
SmartSwitchAuthenticateGameCenter
string gameCenterId = "userGameCenterId";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.SmartSwitchAuthenticateGameCenter(
gameCenterId, forceCreate,
successCallback, failureCallback);
const char* gameCenterId = "userGameCenterId";
_bc->smartSwitchAuthenticateGameCenter(
gameCenterId,
true,
this);
NSString* gameCenterID = @"userGameCenterId";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc smartSwitchAuthenticateGameCenter:gameCenterID
forceCreate:true
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
// N/A
var gameCenterId = "userGameCenterId";
var forceCreate = true;
_bc.smartSwitchAuthenticateGameCenter(gameCenterId, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
Smart Switch Authenticate will logout of the current profile, and switch to the new authentication type. In event the current session was previously an anonymous account, the smart switch will delete that profile. Use this function to keep a clean designflow from anonymous to signed profiles
Authenticate the user using their Game Center id
Method Parameters
Parameter | Description |
---|---|
gameCenterId | The player's game center ID (use the playerID property from the local GKPlayer object) |
forceCreate | Should a new profile be created for this user if the account does not exist? |
SmartSwitchAuthenticateGoogle
string googleId = "g123456789";
string token = "authTokenFromGoogle";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.SmartSwitchAuthenticateGoogle(
googleId, token, forceCreate,
successCallback, failureCallback);
const char* googleId = "g123456789";
const char* token = "authTokenFromGoogle";
_bc->smartSwitchAuthenticateGoogle(
googleId, token, true, this);
NSString* userID = @"g123456789";
NSString* token = @"authTokenFromGoogle";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc smartSwitchAuthenticateGoogle:userID
token:token
forceCreate:true
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String googleId = "g123456789";
String token = "authTokenFromGoogle";
_bc.smartSwitchAuthenticateGoogle(
googleId, token, true, this);
var googleId = "g123456789";
var token = "authTokenFromGoogle";
var forceCreate = true;
_bc.smartSwitchAuthenticateGoogle(googleId, token, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
Smart Switch Authenticate will logout of the current profile, and switch to the new authentication type. In event the current session was previously an anonymous account, the smart switch will delete that profile. Use this function to keep a clean designflow from anonymous to signed profiles
Authenticate the user using a google user id (gXXX) and google authentication token.
Method Parameters
Parameter | Description |
---|---|
googleId | String representation of google userid (gXXX) |
googleToken | The authentication token derived via the google apis. |
forceCreate | Should a new profile be created for this user if the account does not exist? |
SmartSwitchAuthenticateSteam
string steamId = "userSteamId";
string ticket = "sessionTicketFromSteam";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.SmartSwitchAuthenticateSteam(
steamId, ticket, forceCreate,
successCallback, failureCallback);
const char* steamId = "userSteamId";
const char* ticket = "sessionTicketFromSteam";
_bc->smartSwitchAuthenticateSteam(
steamId, token, true, this);
NSString* userID = @"userSteamId";
NSString* sessionticket = @"sessionTicketFromSteam";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc smartSwitchAuthenticateSteam:userID
sessionTicket:sessionticket
forceCreate:true
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
Steam steamId = "userSteamId";
Steam ticket = "sessionTicketFromSteam";
_bc.smartSwitchAuthenticateSteam(
steamId, token, true, this);
var steamId = "userSteamId";
var ticket = "sessionTicketFromSteam";
var forceCreate = true;
_bc.smartSwitchAuthenticateSteam(steamId, ticket, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
Smart Switch Authenticate will logout of the current profile, and switch to the new authentication type. In event the current session was previously an anonymous account, the smart switch will delete that profile. Use this function to keep a clean designflow from anonymous to signed profiles
Authenticate the user using a steam userId and session ticket (without any validation on the userId).
Method Parameters
Parameter | Description |
---|---|
userId | String representation of 64 bit steam ID |
sessionTicket | The session ticket of the user (hex encoded) |
forceCreate | Should a new profile be created for this user if the account does not exist? |
SmartSwitchAuthenticateTwitter
string twitterId = "userTwitterId";
string token = "userAuthToken";
string secret = "secretFromTwitterApi";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.SmartSwitchAuthenticateTwitter(
twitterId, token, secret, forceCreate,
successCallback, failureCallback);
const char* twitterId = "userTwitterId";
const char* token = "userAuthToken";
const char* secret = "secretFromTwitterApi";
_bc->smartSwitchAuthenticateTwitter(
twitterId, token, secret, true, this);
NSString* twitterId = @"userTwitterId";
NSString* token = @"userAuthToken";
NSString* secret = @"secretFromTwitterApi";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc smartSwitchAuthenticateTwitter:userID
token:token
secret:secret
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String twitterId = "userTwitterId";
String token = "userAuthToken";
String secret = "secretFromTwitterApi";
_bc.smartSwitchAuthenticateTwitter(
twitterId, token, secret, true, this);
var twitterId = "userTwitterId";
var token = "userAuthToken";
var secret = "secretFromTwitterApi";
var forceCreate = true;
_bc.smartSwitchAuthenticateTwitter(twitterId, token, secret, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
Smart Switch Authenticate will logout of the current profile, and switch to the new authentication type. In event the current session was previously an anonymous account, the smart switch will delete that profile. Use this function to keep a clean designflow from anonymous to signed profiles
Authenticate the user using a Twitter user ID, authentication token, and secret from Twitter
Method Parameters
Parameter | Description |
---|---|
userId | String representation of Twitter user ID |
token | The authentication token derived via the Twitter APIs |
secret | The secret given when attempting to link with Twitter |
forceCreate | Should a new profile be created for this user if the account does not exist? |
SmartSwitchAuthenticateUniversal
const char* userId = "MyUserName_007";
const char* password = "MyP@ssW0rd!";
bool forceCreate = true;
_bc->smartSwitchAuthenticateUniversal(userId, password, forceCreate, this);
string userId = "MyUserName_007";
string password = "MyP@ssW0rd!";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.SmartSwitchAuthenticateUniversal(userId, password, forceCreate, successCallback, failureCallback);
String userId = "MyUserName_007";
String password = "MyP@ssW0rd!";
boolean forceCreate = true;
_bc.smartSwitchAuthenticateUniversal(userId, password, forceCreate, this);
NSString* userId = @"MyUserName_007";
NSString* password = @"MyP@ssW0rd!";
bool forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[_bc smartSwitchAuthenticateUniversal:userId
password:password
forceCreate:forCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
var userId = "MyUserName_007";
var password = "MyP@ssW0rd!";
var forceCreate = true;
_bc.smartSwitchAuthenticateUniversal(userId, password, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
Smart Switch Authenticate will logout of the current profile, and switch to the new authentication type. In event the current session was previously an anonymous account, the smart switch will delete that profile. Use this function to keep a clean designflow from anonymous to signed profiles
Method authenticates the user using universal credentials
Method Parameters
Parameter | Description |
---|---|
userId | The user's ID. |
password | The password of the user. |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Client API
Authentication
This section describes the key methods for implementing basic authentication in your app. These methods are all you'll need if you:
- Just want to use anonymous authentication for all users
- Want to use a single authentication type (which is required) for all users – i.e. like forced Facebook or GameCenter
- Want to get authentication going quickly during development, and will flesh out more of the authentication details later
Consult the advanced (Identity) section if/when you want to get even more flexible with authentication (giving users more flexibility to choose their preferred authentication method, merging of profiles, etc.) When implementing brainCloud authentication, there are some key things to keep in mind:
brainCloud uses an anonymous installation ID (commonly referred to as the anonymous ID) to identify individual devices. This ID must be generated for first use, and saved by the client application. brainCloud provides a convenient method for generating the ID – or the developer can generate it themselves. brainCloud also requires the client to keep track of the most recent profile ID. This, together with the anonymous ID, provides additional security and allows brainCloud to better understand user intent during logins/reconnections. If the user has never connected before the profile ID should be null.
If you are using the API Explorer, the list of valid Platform IDs can be found here.
Handy tip: To log a user out of brainCloud, use the Logout method in PlayerState. Note that you don't absolutely need to log users out – their sessions will timeout on the server automatically anyway.
By default, the timeout length for authenticated users is 20 minutes. This timeout length can be lowered on the brainCloud Dashboard. [Core App Info | Advance Settings > Session Timeout]
Version Enforcement
brainCloud's authentication mechanisms allow you to enforce minimum client version requirements – forcing users with obsolete versions of your client app to upgrade before continuing within your application. This is especially useful for scenarios where you've fixed critical client errors, made significant changes to the server-side data structures, or generally just want to ensure that your users all have the best possible experience.
The client app version (sometimes referred to as the gameVersion
) is sent to the server during authentication. It is a string of format "X.X" or "X.X.X" – for example, "1.0.0". The app version is set via the Client
or BrainCloudWrapper
Initialize()
methods.
The minimum versions that your app supports can be configured on the Core App Info | Platforms page of the design portal.
If the client app is older than the minimum version specified, authenticate will return a result similar to:
{
"status": 400,
"reason_code": 40322,
"upgradeAppId": "http://itunes.com/apps/myappname",
"status_message": "Processing exception (message): App version 1.0.0 is obsolete."
}
Recommended behavior of the client is to pop up a dialog inviting the user to upgrade the client, and then redirect them to the appropriate software update page. Note that an upgrade URL may be data-filled with the minimum version # in the server portal.
Disabled Apps
brainCloud allows you to easily control whether your app is enabled or disabled via the Core App Info | Advanced Settings page of the portal.
If for some reason you do decide to disable your app, you are able to configure a custom JSON object to be returned to apps that attempt to login. This JSON is set via the [Edit Disabled Reason] button on that same portal page.
{
"message": "Apologies - we will be right back!"
}
Once disabled, your provided JSON-data will be returned within an element called disabledReason
within the error response. For example:
{
"reason_code": 40330,
"status": 403,
"status_message": "Processing exception (bundle): App is disabled.",
"disabledReason": {
"message": "Apologies - we will be right back!"
},
"severity": "ERROR"
}
System Disabled
If for some reason your app is System Disabled by brainCloud operations, your app will receive a disabledReason
with two elements: sysDisabled: true
and message
.
{
"reason_code": 40330,
"status": 403,
"status_message": "Processing exception (bundle): App is disabled.",
"disabledReason": {
"sysDisabled": true,
"message": "This app has been system disabled. Please contact support."
},
"severity": "ERROR"
}
API Summary
Initialization
Authentication
- AuthenticateAnonymous
- AuthenticateUniversal
- AuthenticateEmailPassword
- AuthenticateFacebook
- AuthenticateGameCenter
- AuthenticateGoogle
- AuthenticateHandoff
- AuthenticateSettopHandoff
- AuthenticateSteam
- AuthenticateTwitter
- AuthenticateParse
- AuthenticateExternal
Utility
- ResetEmailPassword
- ResetEmailPasswordAdvanced
- ResetUniversalIdPassword
- ResetUniversalIdPasswordAdvanced
- ClearSavedProfileId
AuthenticateAnonymous
// if it's a new user
const char* newAnonId = _bc->generateGUID();
_bc->initializeIdentity(NULL, newAnonId);
_bc->getAuthenticationService()->authenticateAnonymous(true, this);
// if it's an existing user
const char* savedProfileId = yourMethodToGetSavedProfileId();
const char* savedAnonId = yourMethodToGetSavedAnonymousId();
_bc->initializeIdentity(savedProfileId, savedAnonId);
_bc->getAuthenticationService()->authenticateAnonymous(false, this);
// note you can also use the BrainCloudWrapper class
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.AuthenticationService.AuthenticateAnonymous(forceCreate, successCallback, failureCallback);
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService] authenticateAnonymous:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
boolean includeOffline = true;
this; // implements IServerCallback
_bc.GetAuthenticationService().AuthenticateAnonymous(includeOffline, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var forceCreate = true;
_bc.authentication.authenticateAnonymous(forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
To authenticate anonymously you must have first called InitializeIdentity. You must supply an anonymous ID if you are creating a brand new profile or if you are logging into an already created profile you need to supply the anonymous ID AND the profile ID of the user.
Once you've logged in successfully make sure to save the anonymous and profile ID for future logins.
You can generate a new anonymous ID using the convenience method GenerateAnonymousId.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
forceCreate | If set to true, create a new profile if anonymous ID not found. If set to false and anonymous ID does not exist on the server, return an error. |
public void FailureCallback(int statusCode, int reasonCode, string statusMessage, object cbObject) {
switch (reasonCode) {
case ReasonCodes.MISSING_IDENTITY_ERROR: { // Anonymous id is invalid
// Clear the profile id, generate a new Anonymous id, and re-authenticate
BrainCloudClient.Get().AuthenticationService.ClearSavedProfileID();
BrainCloudClient.Get().AuthenticationService.AnonymousId =
BrainCloudClient.Get().AuthenticationService.GenerateAnonymousId();
BrainCloudClient.Get().AuthenticationService.AuthenticateAnonymous(true, OnSuccess_Authenticate, OnError_AuthenticateAnonymous);
break;
}
case ReasonCodes.MISSING_PROFILE_ERROR: { // Anonymous id doesn't exist in database
// The account doesn't exist - create it now.
BrainCloudClient.Get().AuthenticationService.AuthenticateAnonymous(true, OnSuccess_Authenticate, OnError_AuthenticateAnonymous);
break;
}
case ReasonCodes.SWITCHING_PROFILES: { // Identity belongs to a different profile
// Clear the profile id, generate a new Anonymous id, and re-authenticate
BrainCloudClient.Get().AuthenticationService.ClearSavedProfileID();
BrainCloudClient.Get().AuthenticationService.AnonymousId =
BrainCloudClient.Get().AuthenticationService.GenerateAnonymousId();
BrainCloudClient.Get().AuthenticationService.AuthenticateAnonymous(true, OnSuccess_Authenticate, OnError_AuthenticateAnonymous);
break;
}
case ReasonCodes.SECURITY_ERROR: { // Identity is invalid
// Generate a new Anonymous id, and re-authenticate
BrainCloudClient.Get().AuthenticationService.AnonymousId =
BrainCloudClient.Get().AuthenticationService.GenerateAnonymousId();
BrainCloudClient.Get().AuthenticationService.AuthenticateAnonymous(true, OnSuccess_Authenticate, OnError_AuthenticateAnonymous);
break;
}
case ReasonCodes.MISSING_REQUIRED_PARAMETER: { // Anonymous id cannot be blank
// Generate an Anonymous id before calling AuthenticateAnonymous
BrainCloudClient.Get().AuthenticationService.AnonymousId =
BrainCloudClient.Get().AuthenticationService.GenerateAnonymousId();
BrainCloudClient.Get().AuthenticationService.AuthenticateAnonymous(true, OnSuccess_Authenticate, OnError_AuthenticateAnonymous);
break;
}
default: { // Uncaught reasonCode
/**
* Log the unexpected reasonCode to your own internal logs,
* to implement needed error handling later
*/
break;
}
}
}
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | Both an anonymousId and profileId were provided for authentication - but the anonymousId doesn't exist on the server. The profileId may or may not exist. It is possible that the user account was deleted via the Design Portal. The proper recourse is to reset the stored profile id, and re-authenticate. [There is no need to delete the anonymousId since it doesn't exist on the server anyway.] |
40207 | SWITCHING_PROFILES | This means that the anonymousId provided does point to a profile, but not the same one that was saved in the client. This fails the anonymous security check. For any other authentication type, this might indicate that the user wants to switch accounts (thus the name of the error constant). For anonymous, the only response is to reset both the stored anonymousId and profileId, and then re-authenticate. |
40208 | MISSING_PROFILE_ERROR | The anonymousId provided is not associated with an existing profile and forceCreate = false. To create an account, retry with forceCreate = true. |
40209 | SECURITY_ERROR | Occurs when attempting to authenticate anonymously to an existing user without providing the matching profile ID |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred on authentication |
40358 | MISSING_REQUIRED_PARAMETER | The provided anonymous ID cannot be null |
AuthenticateEmailPassword
string email = "someEmail@somedomain.com";
string password = "userPassword";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.AuthenticationService.AuthenticateEmailPassword(
email, password, forceCreate, successCallback, failureCallback);
const char* email = "someEmail@somedomain.com";
const char* password = "userPassword";
bool forceCreate = true;
_bc->getAuthenticationService()->authenticateEmailPassword(
email,
password,
forceCreate,
this);
NSString * email = @"someEmail@somedomain.com";
NSString * password = @"userPassword";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService]
authenticateEmailPassword:email
password:password
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String email = "someEmail@somedomain.com";
String password = "userPassword";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.getAuthenticationService().authenticateEmailPassword(email, password, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var email = "someEmail@somedomain.com";
var password = "userPassword";
var forceCreate = true;
_bc.authentication.authenticateEmailPassword(email, password, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
Authenticate the user with a custom Email and Password. Note that the client app is responsible for collecting (and storing) the e-mail and potentially password (for convenience) in the client data. For the greatest security, force the user to re-enter their password at each login (or at least give them that option).
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
The e-mail address of the user | |
password | The password of the user |
forceCreate | Should a new profile be created for this user if the account does not exist? |
public void FailureCallback(int statusCode, int reasonCode, string statusMessage, object cbObject) {
switch (reasonCode) {
case ReasonCodes.MISSING_IDENTITY_ERROR: { // Identity does not exist (and client has orphaned profileId)
// Reset profileId and re-authenticate
BrainCloudClient.Get().AuthenticationService.ResetStoredProfileId();
BrainCloudClient.Get().AuthenticationService.AuthenticateEmail(email, password, true);
break;
}
case ReasonCodes.SWITCHING_PROFILES: { // Identity belongs to a different profile
// Reset profileId and re-authenticate
BrainCloudClient.Get().AuthenticationService.ResetStoredProfileId();
BrainCloudClient.Get().AuthenticationService.AuthenticateEmail(email, password, forceCreate);
break;
}
case ReasonCodes.MISSING_PROFILE_ERROR: { // Identity does not exist
// The account doesn't exist - create it now.
BrainCloudClient.Get().AuthenticationService.AuthenticateEmail(email, password, true);
break;
}
case ReasonCodes.TOKEN_DOES_NOT_MATCH_USER: { // User auth information is incorrect
// Display a dialog telling the user that the password provided was invalid,
// and invite them to re-enter the password.
// ...
break;
}
default: { // Uncaught reasonCode
// Log the error for debugging later
// ...
break;
}
}
}
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Most often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user's password is incorrect. |
AuthenticateExternal
string userId = "externalId";
string token = "externalTokenOrPassword";
string externalAuthName = "nameOfExternalAuthService";
bool includeOffline = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.AuthenticationService.AuthenticateExternal(
userId, token, externalAuthName, forceCreate,
successCallback, failureCallback);
const char* userId = "externalId";
const char* token = "externalTokenOrPassword";
const char* externalAuthName = "nameOfExternalAuthService";
bool forceCreate = true;
_bc->getAuthenticationService()->authenticateExternal(
userId,
token,
externalAuthName,
forceCreate,
this);
NSString * userID = @"externalId";
NSString * token = @"externalTokenOrPassword";
NSString * externalAuthName = @"nameOfExternalAuthService";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService]
authenticateExternal:userID
authenticationToken:authToken
externalAuthenticationName:externalAuthName
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String userID = "externalId";
String token = "externalTokenOrPassword";
String externalAuthName = "nameOfExternalAuthService";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.getAuthenticationService().authenticateExternal(userID, token, externalAuthName, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var userID = "externalId";
var token = "externalTokenOrPassword";
var externalAuthName = "nameOfExternalAuthService";
var forceCreate = true;
_bc.authentication.authenticateExternal(userID, token, externalAuthName, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
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.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
userId | The userId |
token | The user token (password etc) |
externalAuthName | The name of the cloud script to call for external authentication |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials don't match (according to the 3rd party system). May also indicate an issue with the external authentication script. |
AuthenticateFacebook
string facebookId = "userFacebookId";
string token = "tokenFromFacebook";
bool forceCreate = true;
_bc.AuthenticationService.AuthenticateFacebook(
facebookId, token, forceCreate, SuccessCallback, FailureCallback);
const char* facebookId = "userFacebookId";
const char* token = "tokenFromFacebook";
bool forceCreate = true;
_bc->getAuthenticationService()->authenticateFacebook(
facebookId,
token,
forceCreate,
this);
NSString * facebookId = @"userFacebookId";
NSString * token = @"tokenFromFacebook";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService]
authenticateFacebook:facebookId
authenticationToken:token
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String facebookId = "userFacebookId";
String token = "tokenFromFacebook";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.getAuthenticationService().authenticateFacebook(facebookId, token, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var facebookId = "userFacebookId";
var token = "tokenFromFacebook";
var forceCreate = true;
_bc.authentication.authenticateFacebook(facebookId, token, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
Authenticate the user with brainCloud using their Facebook Credentials.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
facebookId | The Facebook ID of the user |
facebookToken | The validated token from the Facebook SDK |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials are invalid (i.e. bad Facebook id / token). May also indicate that Facebook integration is not properly configured. |
AuthenticateGameCenter
string gameCenterId = "userGameCenterId";
bool forceCreate = true;
_bc.AuthenticationService.AuthenticateGameCenter(
gameCenterId, forceCreate, SuccessCallback, FailureCallback);
const char* gameCenterId = "userGameCenterId";
bool forceCreate = true;
_bc->getAuthenticationService()->authenticateGameCenter(
gameCenterId,
forceCreate,
this);
NSString * gameCenterID = @"userGameCenterId";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService]
authenticateGameCenter:gameCenterID
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
// N/A
var gameCenterID = "userGameCenterId";
var forceCreate = true;
_bc.authentication.authenticateGameCenter(gameCenterID, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
Authenticate the user using their Game Center ID.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
gameCenterId | The player's game center ID (use the playerID property from the local GKPlayer object) |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the design portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials are invalid (i.e. bad gameCenterId ) |
AuthenticateGoogle
string googleId = "g123456789";
string googleToken = "authTokenFromGoogle";
bool forceCreate = true;
_bc.AuthenticationService.AuthenticateGoogle(
googleId, googleToken, forceCreate, SuccessCallback, FailureCallback);
const char* googleId = "g123456789";
const char* googleToken = "authTokenFromGoogle";
bool forceCreate = true;
_bc->getAuthenticationService()->authenticateGoogle(
googleId, googleToken, forceCreate, this);
NSString * googleId = @"g123456789";
NSString * googleToken = @"authTokenFromGoogle";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService]
authenticateGoogle:googleId
authenticationToken:googleToken
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String googleId = "g123456789";
String googleToken = "authTokenFromGoogle";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.getAuthenticationService().authenticateGoogle(googleId, googleToken, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var googleId = "g123456789";
var googleToken = "authTokenFromGoogle";
var forceCreate = true;
_bc.authentication.authenticateGoogle(googleId, googleToken, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
Authenticate the user using a google user ID (gXXX) and google authentication token.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
googleId | String representation of google userid (gXXX) |
googleToken | The authentication token derived via the google apis. |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials are invalid (i.e. googleId and googleToken are invalid). May also indicate that Google Integration is not properly configured. |
AuthenticateHandoff
string handoffId = "handoffId";
string secruityToken = "secruityToken";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.AuthenticationService.AuthenticateHandoff(
handoffId, secruityToken, forceCreate, successCallback, failureCallback);
const char* handoffId = "handoffId";
const char* secruityToken = "secruityToken";
bool forceCreate = true;
_bc->getAuthenticationService()->authenticateHandoff(
handoffId,
secruityToken,
forceCreate,
this);
NSString* handoffId = @"handoffId";
NSString* secruityToken = @"secruityToken";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService]
authenticateHandoff:handoffId
secruityToken:secruityToken
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String handoffId = "handoffId";
String secruityToken = "secruityToken";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.getAuthenticationService().authenticateHandoff(handoffId, secruityToken, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var handoffId = "handoffId";
var secruityToken = "secruityToken";
var forceCreate = true;
_bc.authentication.authenticateHandoff(handoffId, secruityToken, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
Authenticate the user with a custom Authentication Handoff.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
handoffId | The id for the given handoff |
secruityToken | The secruity token used to verify the handoff |
forceCreate | Should a new profile be created for this user if the account does not exist? |
public void FailureCallback(int statusCode, int reasonCode, string statusMessage, object cbObject) {
switch (reasonCode) {
case ReasonCodes.MISSING_IDENTITY_ERROR: { // Identity does not exist (and client has orphaned profileId)
// Reset profileId and re-authenticate
BrainCloudClient.Get().AuthenticationService.ResetStoredProfileId();
BrainCloudClient.Get().AuthenticationService.AuthenticateEmail(email, password, true);
break;
}
case ReasonCodes.SWITCHING_PROFILES: { // Identity belongs to a different profile
// Reset profileId and re-authenticate
BrainCloudClient.Get().AuthenticationService.ResetStoredProfileId();
BrainCloudClient.Get().AuthenticationService.AuthenticateEmail(email, password, forceCreate);
break;
}
case ReasonCodes.MISSING_PROFILE_ERROR: { // Identity does not exist
// The account doesn't exist - create it now.
BrainCloudClient.Get().AuthenticationService.AuthenticateEmail(email, password, true);
break;
}
case ReasonCodes.TOKEN_DOES_NOT_MATCH_USER: { // User auth information is incorrect
// Display a dialog telling the user that the password provided was invalid,
// and invite them to re-enter the password.
// ...
break;
}
default: { // Uncaught reasonCode
// Log the error for debugging later
// ...
break;
}
}
}
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Most often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user's password is incorrect. |
AuthenticateParse
string parseId = "someId1234";
string token = "authToken";
bool forceCreate = true;
_bc.AuthenticationService.AuthenticateParse(
parseId, token, forceCreate, SuccessCallback, FailureCallback);
const char* parseId = "someId1234";
const char* token = "authToken";
bool forceCreate = true;
_bc->getAuthenticationService()->authenticateParse(
parseId, token, forceCreate, this);
NSString * userID = @"someId1234";
NSString * authToken = @"authToken";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService]
authenticateParse:userID
token:authToken
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String parseUserId = "someId1234";
String parseAuthToken = "authToken";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.getAuthenticationService().authenticateParse(googleId, googleToken, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var parseUserId = "someId1234";
var parseAuthToken = "authToken";
var forceCreate = true;
_bc.authentication.authenticateParse(googleId, googleToken, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
Authenticate the user using a Parse user ID and authentication token.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
parseId | String representation of Parse user ID |
parseToken | The authentication token from Parse |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user credentials are invalid (i.e. parseId and parseToken are invalid). May also indicate that Parse Integration is not properly configured. |
AuthenticateSettopHandoff
string handoffCode = "handoffCode";
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.AuthenticationService.AuthenticateSettopHandoff(
handoffCode, successCallback, failureCallback);
const char* handoffCode = "handoffCode";
_bc->getAuthenticationService()->authenticateSettopHandoff(
handoffCode,
this);
NSString* handoffCode = @"handoffCode";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService]
authenticateSettopHandoff:handoffCode
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String handoffCode = "handoffCode";
this; // implements IServerCallback
_bc.getAuthenticationService().authenticateSettopHandoff(handoffCode, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var handoffCode = "handoffCode";
_bc.authentication.authenticateSettopHandoff(handoffCode, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"abTestingId": 48,
"lastLogin": 1572446599748,
"server_time": 1572446599779,
"refundCount": 0,
"timeZoneOffset": -5,
"experiencePoints": 0,
"maxBundleMsgs": 12,
"createdAt": 1572446599168,
"parentProfileId": null,
"emailAddress": null,
"experienceLevel": 0,
"handoffJson": {"key": "value"},
"countryCode": "CA",
"vcClaimed": 0,
"currency": {
"test": {
"consumed": 0,
"balance": 0,
"purchased": 0,
"awarded": 0
},
"credits": {
"consumed": 0,
"balance": 0,
"purchased": 0,
"awarded": 0
}
},
"id": "5e04aa28-4c1f-45c2-b32c-3f52c59cfb49",
"compressIfLarger": 0,
"amountSpent": 0,
"previousLogin": 1572446599171,
"playerName": "",
"pictureUrl": null,
"incoming_events": [],
"sessionId": "b9rr6j32ragmhnp5aajbi8vn82",
"languageCode": "en",
"vcPurchased": 0,
"isTester": false,
"summaryFriendData": null,
"loginCount": 2,
"xpCapped": false,
"profileId": "5e04aa28-4c1f-45c2-b32c-3f52c59cfb49",
"newUser": "false",
"playerSessionExpiry": 60,
"sent_events": [],
"maxKillCount": 11,
"rewards": {
"rewardDetails": {},
"currency": {},
"rewards": {}
},
"statistics": {
"wins": 0,
"gamesLost": 0,
"stat2": 0,
"gamesPlayed": 0,
"TestStat": 0,
"highestScore": 0,
"currency": 0,
"losses": 0,
"TestStat2": 0,
"gamesWon": 0
}
}
}
Authenticate the user with a custom Set-top Handoff Code - which is an short, easy-to-enter code suitable for use in devices with limited data entry capabilities (i.e. Set-top boxes, VR headsets, etc.) The hand-off code can be generated via the CreateSettopHandoffCode cloud-code call.
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
handoffCode | The set-top hand-off code generated via CreateSettopHandoffCode |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when forceCreate is true and a saved [but un-associated] profileId is provided. The error handler should reset the stored profile id (if there is one) and re-authenticate, setting forceCreate to true to create a new account. A common cause of this error is deleting the user's account via the Design Portal. |
40207 | SWITCHING_PROFILES | Indicates that the identity credentials are valid, and the saved profileId is valid, but the identity is not associated with the provided profileId . This may indicate that the user wants to switch accounts in the app. Most often an app will pop-up a dialog confirming that the user wants to switch accounts, and then reset the stored profileId and call authenticate again. |
40208 | MISSING_PROFILE_ERROR | Returned when the identity cannot be located, no profileId is provided, and forceCreate is false. The normal response is to call Authenticate again with forceCreate set to true . |
40217 | UNKNOWN_AUTH_ERROR | An unknown error has occurred during authentication. |
40307 | TOKEN_DOES_NOT_MATCH_USER | The user's password is incorrect. |
AuthenticateSteam
string steamId = "userSteamId";
string sessionTicket = "sessionTicketFromSteam";
bool forceCreate = true;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Success] {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Authenticate Failed] {0} {1} {2}", status, code, error));
};
_bc.AuthenticationService.AuthenticateSteam(
steamId, tisessionTicketcket, forceCreate,
successCallback, failureCallback);
const char* steamId = "userSteamId";
const char* sessionTicket = "sessionTicketFromSteam";
_bc->getAuthenticationService()->authenticateSteam(
steamId, sessionTicket, true, this);
NSString * steamId = @"userSteamId";
NSString * sessionTicket = @"sessionTicketFromSteam";
BOOL forceCreate = true;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc authenticationService]
authenticateSteam:steamId
sessionTicket:sessionTicket
forceCreate:forceCreate
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String steamId = "userSteamId";
String sessionTicket = "sessionTicketFromSteam";
boolean forceCreate = true;
this; // implements IServerCallback
_bc.getAuthenticationService().authenticateSteam(steamId, sessionTicket, forceCreate, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var steamId = "userSteamId";
var sessionTicket = "sessionTicketFromSteam";
var forceCreate = true;
_bc.authentication.authenticateSteam(steamId, sessionTicket, forceCreate, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
// N/A
{
"status": 200,
"data": {
"vcPurchased": 0,
"experiencePoints": 100,
"refundCount": 0,
"playerSessionExpiry": 60,
"server_time": 1464621990155,
"experienceLevel": 0,
"currency": {
"credits": {
"purchased": 0,
"balance": 12211,
"consumed": 133,
"awarded": 12344
}
},
"abTestingId": 8,
"statistics": {
"gamesWon": 0
},
"id": "323e861-b749-4ce4-a57a-175232e21b5d",
"createdAt": 1459439058035,
"profileId": "323e861-b749-4ce4-a57a-175232e21b5d",
"newUser": "false",
"xpCapped": false,
"sent_events": [],
"timeZoneOffset": -5,
"playerName": "",
"vcClaimed": 0,
"parentProfileId": null,
"rewards": {
"rewardDetails": {},
"rewards": {},
"currency": {}
},
"countryCode": "ca",
"loginCount": 16,
"emailAddress": "test@email.com",
"previousLogin": 1464621979514,
"incoming_events": [],
"lastLogin": 1464621990118,
"languageCode": "en",
"pictureUrl": null,
"sessionId": "v3grtg3ve0a089pekk8lneuk8k",
"amountSpent": 0
}
}
Authenticate the user using a steam userId and session ticket (without any validation on the userId).
Service | Operation |
---|---|
"authenticationV2" | "AUTHENTICATE" |
Method Parameters
Parameter | Description |
---|---|
userId | String representation of 64 bit steam ID |
sessionTicket | The session ticket of the user (hex encoded) |
forceCreate | Should a new profile be created for this user if the account does not exist? |
Status Codes
Code | Name | Description |
---|---|---|
40206 | MISSING_IDENTITY_ERROR | The identity does not exist on the server and forceCreate was false [and a profileId was provided - otherwise 40208 would have been returned]. Will also occur when |