Search⌘ K

Authorization

Explore how to secure Phoenix Channels by implementing authorization rules that limit channel access to two distinct players using Presence. Understand how to write functions to check player counts and screen name uniqueness, enabling you to control who can join in real time. This lesson shows practical use of Presence and channel join logic to maintain a stateful, authorized connection in an Elixir web application.

Permissible actions

In this last lesson, we tackle authorization: deciding if an action is permissible. The action we really care about is joining a Channel. The rules for this are simple. We want only two players to join a Channel on any given topic-subtopic and also want those two players to have different screen names.

Authentication resources

In Islands, we don’t need authentication—determining if users are who they say they are. If your application needs authentication, there are resources out there to help. Check out the documentation for Phoenix.Token if token-based authentication is needed.

Now that we have Presence, we can write functions to check both of the authorization conditions we outline. We can roll them into a single function that determines whether a given player can join.

The first condition we need to check is the number of ...