SmartSwitchAuthenticateExternal
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? |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
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));
});
var userId = "externalId";
var token = "externalTokenOrPassword";
var externalAuthName = "nameOfExternalAuthService";
var forceCreate = true;
ServerResponse result = await _bc.smartSwitchAuthenticateExternal(
userId:userId,
token:token,
externalAuthName:externalAuthName,
forceCreate:forceCreate);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
// N/A
// N/A
JSON Response
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));
});