function handle_auth_response($response) { if ($response['stat'] == "ok") { trigger_error("Authenticated user. UUID: {$response['capture_user']['uuid']}"); trigger_error("Exchanging authorization code: {$response['authorization_code']}"); $tokens = janrain_exchange_authorization_code($response['authorization_code']); janrain_set_session_data($tokens, $response['capture_user']); return array('status' => 'success', 'data' => janrain_get_client_side_session_data()); } else { if ($response['error'] == 'invalid_credentials') { return array('status' => 'error', 'message' => $response['invalid_fields']['signInForm'][0], 'code' => $response['code'], 'data' => $response); } else { return array('status' => 'error', 'message' => $response['error_description'], 'code' => $response['code'], 'data' => $response); } } }
<?php /** * Endpoint to fetch session data that can be exposed client-side. * JSON response. */ require_once "janrain.php"; header('Content-Type: application/json'); ini_set('display_errors', False); session_start(); echo json_encode(array('status' => 'success', 'data' => janrain_get_client_side_session_data()));