Access control in CloudBehaviours
Restrict which callers are allowed to invoke a CloudBehaviour endpoint.
Read time 2 minutesLast updated 14 days ago
Every CloudBehaviour endpoint has an access level. By default, Cloud Code resolves it from the class's : a class defaults to , and a class defaults to . Add only where a specific endpoint needs to differ from that default:
[StateScope]Scope.PlayerAccess.PlayerScope.MultiplayerSessionAccess.SessionMember[CloudCodeAccess][StateScope(Scope.MultiplayerSession)]public class MatchState : CloudBehaviour{ public void SubmitMove(string move) { } // Access.SessionMember (default) [CloudCodeAccess(Access.SessionHost)] public void StartMatch() { } // Only the session host [CloudCodeAccess(Access.Service)] public void GrantReward(string playerId, int amount) { } // Only service-token callers}
The Access enum
Which values are valid depends on the class's :
[StateScope]Value | 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 |
An value that a class's scope can't support throws when the module loads.
AccessChoose a level
Use on anything that mints value, such as granting currency or awarding items. Use for match flow control, such as starting or force-advancing a match, where one client is authoritative. Beyond those cases, the scope's default access level is usually correct.
Access.ServiceSessionHost