Skip to main content
Version: 5.7.0

AuthenticateUniversal

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.

Error Handling Example

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;
}
}
}
caution

You must initialize the brainCloud wrapper in order to authenticate.

ServiceOperation
authenticationV2AUTHENTICATE

Method Parameters

ParameterDescription
userIdThe user's ID.
passwordThe password of the user.
forceCreateShould a new profile be created for this user if the account does not exist?

Usage

http://localhost:3000
string userId = "userName";
string password = "password";
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);
JSON Response
{
"data": {
"abTestingId": 95,
"lastLogin": 1713973000159,
"server_time": 1713973000235,
"refundCount": 0,
"timeZoneOffset": -5.0,
"experiencePoints": 0,
"maxBundleMsgs": 10,
"createdAt": 1713973000153,
"parentProfileId": null,
"emailAddress": "test@email.com",
"experienceLevel": 1,
"countryCode": null,
"vcClaimed": 0,
"currency": {
"bar": {
"consumed": 0,
"balance": 0,
"purchased": 0,
"awarded": 0,
"revoked": 0
},
"coins": {
"consumed": 0,
"balance": 8,
"purchased": 0,
"awarded": 8,
"revoked": 0
}
},
"id": "15e5ce33-2411-45f8-a29e-7f600880113a",
"compressIfLarger": 51200,
"amountSpent": 0,
"previousLogin": null,
"playerName": "",
"pictureUrl": null,
"incoming_events": [],
"sessionId": "gbgakmm4hmt15e2pobvmh7ptck",
"languageCode": "en",
"vcPurchased": 0,
"isTester": false,
"summaryFriendData": null,
"loginCount": 1,
"emailVerified": true,
"xpCapped": false,
"profileId": "15e5ce33-2411-45f8-a29e-7f600880113a",
"newUser": "true",
"playerSessionExpiry": 1200,
"sent_events": [],
"maxKillCount": 11,
"rewards": {
"rewardDetails": {
"xp": {
"experienceLevels": [
{
"level": 1,
"rewards": {
"currency": {
"coins": 8
}
}
}
]
}
},
"currency": {
"bar": {
"consumed": 0,
"balance": 0,
"purchased": 0,
"awarded": 0,
"revoked": 0
},
"coins": {
"consumed": 0,
"balance": 8,
"purchased": 0,
"awarded": 8,
"revoked": 0
}
},
"rewards": {}
},
"statistics": {
"test": 0.99,
"HITLEVELNVEHICLE_000005": 0
}
},
"status": 200
}
Common Error Code

Status Codes

CodeNameDescription
40206MISSING_IDENTITY_ERRORThe 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.
40207SWITCHING_PROFILESIndicates 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.
40208MISSING_PROFILE_ERRORReturned 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.
40217UNKNOWN_AUTH_ERRORAn unknown error has occurred during authentication.
40307TOKEN_DOES_NOT_MATCH_USERThe user credentials don't match (i.e. incorrect password).