This sample demonstrates redirecting HTTP requests and using Facebook Authentication, Facebook JavaScript SDK to login the user and show his photos.
The sample solution is already configured and you only have to compile and run it.
It uses a sample mini game framework that provides very basic functionality.
The output will be in the Coherent/Samples/UI/bin directory.
This sample builds upon the Input in 2D sample and assumes that you understand it.
Coherent::UI::View::InterceptURLRequests
is activated;ViewEventListener
overrides Coherent::UI::ViewListener::OnURLRequest
Coherent::UI::ViewContext
is initialized with cookies supportCreate a view context, enabling support for cookies.
Using coui:// for cookies allows loading and saving of cookies via Coherent::UI::FileHandler
.
When the view is created interception of URL requests is activated:
This forces all URL requests to go through the Coherent::UI::ViewListener::OnURLRequest
method allowing to allow / deny / redirect requests.
As explained by the Facebook documentation to obtain an access token for a user you have to
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_FACEBOOK_APP_LOGIN_URL&response_type=token
https://www.facebook.com/connect/login_success.html#access_token=USER_ACCESS_TOKEN
Here is the acturl OnURLRequest
handler that handles this redirection:
The HTML and Javascript code for this sample is in Coherent/Samples/UI/bin/html/facebook.html.
If there is no hash part in the URL the sample shows a login button. When the button is clicked the view will be redirected to https://www.facebook.com/dialog/oauth with all the appropriate arguments, requesting client access token, signed request, refresh code to be returned and access to the user's photos.
Then the users authorizes your application, the view will be redirected to YOUR_FACEBOOK_APP_LOGIN_URL::access_token=...
. This redirection is handled by EventViewListener::OnURLRequest
and the view is redirected to coui://html/facebook.html::access_token=...
. The page detects that it has been loaded with the access_token and loads the Facebook JavaScript SDK asynchronously.
When the SDK is loaded, attach handlers to the auth.LoginResponse
events and initialize the SDK with the provided access token
The rest of the sample creates a rotating 3D circle of the user's photos and shows a photo when its thumbnail is clicked.