All Collections
Portal-X Pages
Design | Authentication | Shared Accounts
Design | Authentication | Shared Accounts

Shared Accounts allow the profiles from one app (the parent) to be used as authentication for a second (child) app.

Jason Liang avatar
Written by Jason Liang
Updated over a week ago

The Shared Accounts feature is a powerful example of the flexibility of brainCloud’s authentication architecture. brainCloud already provides a myriad of authentication options: anonymous, e-mail address, Facebook ID, Google ID, GameCenter, Twitter, etc. brainCloud can even authenticate users with external directories via our External Authentication feature. Shared Accounts takes this one step further, allowing you to create a single, shared account system for your users to access all (or select) company apps. You will then have a single repository of your users, regardless of the specific app they are using. This is useful to offer common, shared features across all apps – like shared premium currencies, meta-level leaderboards, achievements, etc. – anything you want. For more information, please refer to our documentation -- Shared Account.

Set Parent App

  • To get started, from the portal Team | Manage | Apps page, select or create a new app as a parent app, then go to page Design | Authentication | Shared Accounts.

  • Check the [ Can be a Parent] checkbox, enter a name for the identifier of this parent app, and click Save.

Set Child App

  • Select an existing app or create an app as the child app from the portal Team | Manage | Apps page, then go to Design | Authentication | Shared Accounts page of this app.

  • Check the [ Is a Child of] checkbox, select a parent app from the drop-down menu, and click Save.

Authenticating Users

  • Switch back to the parent app and go to the Design | Cloud Code | API Explorer page, using the API Explore authenticate service to authenticate a user in the parent app.

  • Select Identity Service and SwitchToChildProfile() API, put the child appId to the correspondent parameter, and click Run.

  • Switch back to the child app and go to Users | Summary | User Summary page to check this newly created user on the child app.

Call APIs

  • Click the [Login As User] button beside the avatar pic that will redirect you to the Design | Cloud Code | API Explorer page, now, you are ready to go with using API Explore all API calls that behave the same way as they do for any other brainCloud app.

  • Check this current user's Virtual Currency on the Users | Marketplace | Virtual Currency page, you will find the corresponding user's currencies in the parent app.

  • Go back to the Design | Cloud Code | API Explorer page, and check the current user state by calling ReadUserState() for the later comparison after switching to the parent user. As you can see there is an extra parentCurrency field displayed on the response for this user with a parent profile.

  • Retain on the same page, call the SwitchToParentProfile() API of the Identity service, then call ReadUserState() again to compare the difference of the result at this point. As you can see, now we are on the parent app! So whatever you do here is just the same as you do on the parent app.

  • Call the GetChildProfiles() API of the Identity service to show you the list of child profiles that are related to this parent user.

  • Test to increase user statistics by calling IncrementUserStats() API, putting statistics name/value pair as a parameter, and seeing the returned result. Note that these statistics exist in the parent app.

  • Calling SwitchToChildProfile() API of the Identity service switches back to the current level user at any time.

  • Call the GetCurrency() API of the Product service to check the current currency balances of this child user and related parent user. (put null for currency type).

  • With this child current user, you can call parent scripts by calling RunParentScript() API of ScriptService Service, this client callable script will be executed as the corresponding parent user.

Note: that brainCloud will automatically adjust the server context to make the appropriate parent profile (as identified by the <app_level> current before running the script), and return it to the prior app level when the script is complete.

Other few more API calls can be called directly from the child app to the parent app level without calling SwitchToParentProfile():

  • AwardParentCurrency() – allows you to increment the currency balance of the specified parent-level currency

  • ConsumeParentCurrency() – allows you to decrement the balance of the specified parent-level currency

  • GetParentCurrency() – retrieves the current balance of the specified parent-level currency (note: also returned in Authentication and Player State )

  • ResetParentCurrency() – resets all currency balances at the specified parent level (mostly useful for testing/debugging)

Did this answer your question?