This tutorial gives a walk through on how to authenticate a user in a Photon Cloud application with his Facebook credentials using Photon Custom Authentication.
Photon Cloud Custom Authentication involves calling an external service (Authentication Provider) to check user authentication. For an outline of the authentication flow, please check our general documentation.
Enabling Custom Authentication for an existing application involves a few simple steps:
1. Facebook App Setup
Reference the Facebook documentation for details on Facebook App setup. For this tutorial you need your Facebook App ID and App Secret.
2. Photon Cloud Application
Go to the Details page of your application via your Photon Cloud Dashboard. Expand the Custom Authentication section. The Authentication URL for Facebook authentication is set by Exit Games.
Set the values for these two parameters:
- appid = your Facebook App ID
- secret = your Facebook App Secret
The client needs to pass Add a Facebook Login button div anywhere inside your html document body.
window.fbAsyncInit is called after loading completed.
It subscribes a handler on Facebook
auth.authResponseChange event, which gets fired with
response.status = "connected" after the user successfully logged in to Facebook.
The user's token gets passed to the handler as parameter.
Having this token, the handler sets Custom Authentication mode for the client and adds the additional parameter token to the authentication URL.
Then the handler starts a connection to the Master server.
4. Deploy and Run
User accessing your application page will log in to Photon Cloud after pressing the Facebook Login button and entering their username/password. If already logged in at Facebook, they will be signed in to Photon Cloud immediately.