Authentication
A BaaS is only as flexible as its identity system - and brainCloud is very flexible indeed. The brainCloud authentication and identity APIs have been designed with the following goals in mind:
- Allow developers to include both anonymous and authenticated access to their apps
- Allow access to multiple authentication mechanisms - so as not to alienate any significant user bases
- Include support for merging accounts (which is commonly needed when games are offered across various device platforms)
brainCloud supports the following types of identities:
- Anonymous
- Authenticated
- Game Center (iOS)
- Google Play Services
- E-mail + Password
- Universal Userid + Password (meant for development primarily - has limitations)
- Steam
And we're always adding new ones! (Indeed, we've recently added support for External Authentication and Shared Accounts as well!)
Important note - there are no global brainCloud Accounts for end-users. All end-user accounts (profiles) are local to the app they are associated with - we do this so that you completely own your end-user data, and there is no branding-confusion regarding the accounts.
Key Concepts
These key concepts are essential to understanding brainCloud authentication:
- Profile - all the key information about a user in your game or app is stored in the Profile. The profile is the key record for locating a users stats, entities, achievements, currency balances, etc.
- Identities - brainCloud uses identities to locate profiles. Every brainCloud profile has at least one identity (the anonymous identity) associated with it - but it may have others (including a Facebook identity, Game Center identity, etc.)
- Logging in - when your app starts, it logs into brainCloud by providing an identity for brainCloud to use to locate the appropriate profile.
- Advanced operations - brainCloud provides advanced APIs to allow you to add additional identities to a profile after it's been created - and can even allow you to merge profiles where necessary.
Creating Profiles
There is no explicit Create() and Delete() methods for brainCloud profiles - instead, they are automatically created during authentication if an existing profile cannot be found.
Essentially, the client attempts to log into brainCloud using the selected authentication mechanism - and if an existing profile is not located, a new one will automatically be created. [Technically speaking, the developer can choose to override this behavior by passing a FALSE to the forceCreate parameter, but that's not common usage.]
Here's an example using anonymous authentication.
// Authenticate with brainCloud anonymously
// - if a profile for this anonymous id isn't found, create it
BrainCloudWrapper.GetInstance().AuthenticateAnonymous(
true,
OnSuccess_Authenticate,
OnError_Authenticate);
Anonymous Identity and Profile Ids
As we mentioned above, Identities are used to lookup Profiles. A key feature of brainCloud is that it supports user anonymity - so that even if users choose not to identify themselves, we can still associate them with their profile in our system.
To support this, brainCloud generates completely random (GUID-based) ids that are used to identify the device that a profile is connected to. We generate (and have the client store) this id so that we're not breaking any rules about identifying users without their permission - e.g. the same reason developers are no longer allowed to use UDIDs in iOS.
To keep things secure, the AnonymousIdentity must be used in conjunction with the ProfileId to look up the profile. Yes, you got that right - to look up a profile anonymously, you need to already have the profile's id - which you get when the profile is first created. Honestly, this isn't as crazy as it sounds - by requiring these two pieces of information we're preventing folks from hacking into our system and accessing any arbitrary user profile via a single identifier.
The nice thing is that the BrainCloudWrapper class stores both the AnonymousIdentity and the ProfileId for you - so you don't normally have to worry about it.
Anonymous identities are convenient - you don't need to bother your user with a login, yet can still persist their data on the cloud - but there are some significant disadvantages.
Cons of Anonymous Identification
- The user's cloud data will become inaccessible if they lose or wipe their device
- The user cannot access their profile from multiple devices (we're working on that)
- It is more difficult to participate in social features (i.e. friends, invites, etc.)
Authenticated Identities
brainCloud also supports a variety of authenticated identities - including Facebook, E-mail + Password, etc. With authentication comes significant advantages:

