Skip to main content
Version: Next

Authentication

The Authentication mechanism is based on a bearer token. How does it work? Both Fishjam and Business Logic are configured with the same secret. This secret is used for authorizing HTTP requests between them (via HTTP authorization request header). When a new client wants to join a room, Business Logic (assuming the client is authorized to join) requests adding a new peer and receives a token generated by Fishjam. The token must then be passed to the client, that will use it to connect to the room as a new peer. The token encodes both peer and room IDs. The token exchange is handled by our Client SDKs when connecting. Under the hood, Fishjam expects the token in the first message after opening the Web Socket connection.

Token encodes peer id and room id.

  1. Run Fishjam
FJ_SERVER_API_TOKEN=FJ_SERVER_API_TOKEN mix phx.server
  1. Create a room and add one peer
Business Logic
client = Fishjam.Client.new("http://address-of-your-server.com", "FJ_SERVER_API_TOKEN")
{:ok, room, _fishjam_address} = Fishjam.Room.create(client, max_peers: 10)
{:ok, %{peer: peer, token: peer_token, websocket_url: websocket_url}} = Fishjam.Room.add_peer(client, room.id, "BobId")
  1. Connect as a peer to Fishjam
Client
client.connect({ 
token: peerToken,
peerMetadata: { name: "Bob" },
isSimulcastOn: false
})