Access control in CloudBehaviours
Understand the access levels that control which callers can call a CloudBehaviour endpoint, and when to use each one.
Read time 2 minutesLast updated 12 days ago
Every CloudBehaviour endpoint has an access level. By default, Cloud Code resolves the access level from the class's . A class defaults to , and a class defaults to .
[StateScope]Scope.PlayerAccess.PlayerScope.MultiplayerSessionAccess.SessionMemberOverride the default access level
Add only where a specific endpoint needs to differ from the scope's default. The following example keeps the default on one endpoint and overrides it on two others:
[CloudCodeAccess][StateScope(Scope.MultiplayerSession)]public class MatchState : CloudBehaviour{ // This endpoint uses the default access level, Access.SessionMember. public void SubmitMove(string move) { } // Only the session host can call this endpoint. [CloudCodeAccess(Access.SessionHost)] public void StartMatch() { } // Only non-player callers, such as a timer, can call this endpoint. [CloudCodeAccess(Access.Service)] public void EndTurn(int turnNumber) { }}
Access levels
The following table lists each value, the scopes it's valid on, and who can call an endpoint that uses it:
AccessValue | Valid on | Who can call |
|---|---|---|
| Any scope | Resolves from the class scope at load time (the default): |
| Any scope | Any authenticated caller |
| Any scope | Non-player callers only, such as other CloudBehaviours, service accounts, or trusted backends, never a player |
| | The player who owns the scope, and any non-player caller |
| | Any member of the session, and any non-player caller |
| | The host of the session, and any non-player caller |
If you set an value that the class's scope doesn't support, the module throws an exception when it loads.
AccessChoose an access level
Use on an endpoint that only a non-player caller has a reason to call, such as a timer callback, or an endpoint that another CloudBehaviour calls to update a player's record. If logic only runs as part of another endpoint, such as granting gold when a player makes a move, make it a private method instead. A private method isn't an endpoint, so no client can call it. Use for match flow control, such as starting or force-advancing a match, where one client is authoritative. In other cases, the scope's default access level is usually correct.
Access.ServiceAccess.SessionHostFor example, clients can't call an endpoint, but they still receive the synchronized state that the endpoint changes.
Access.Service