<?php

/**
 * Main entry point. Acts as my sample application aguillage.
 */
ini_set('display_errors', 1);
require_once 'config.php';
require_once 'Component/Session.php';
require_once 'Component/DatabaseConnection.php';
require_once '../src/Medical/OAuth/Client.php';
use Medical\OAuth\Client;
// create the 360 client to handle API/OAuth calls
$client = new Client(array('clientId' => CLIENT_ID, 'clientSecret' => CLIENT_SECRET, 'redirectUri' => REDIRECT_URI));
// set production url
$client->setApiUrl('//beta.360medical.fr/app_dev.php');
/**
 * Start your own logic
 */
$session = new Session();
$myStorage = new DatabaseConnection(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// $_SESSION['user_id'] = 1;
// first check if a user exists on your application
if (true === $session->isLoggedIn()) {
    $myUser = $myStorage->getUser($session->getUserId());
    if ($myUser) {
        include 'templates/logged_in.php';
        // the the user is not logged in
    } else {
        include 'templates/logged_out.php';
        // the the user logged in
    }
<?php

ini_set('display_errors', 1);
require_once 'config.php';
require_once 'Component/Session.php';
require_once 'Component/DatabaseConnection.php';
require_once '../src/Medical/OAuth/Client.php';
require_once '../src/Medical/OAuth/Client.php';
use Medical\OAuth\Client;
// create the 360 client to handle API/OAuth calls
$client = new Client(array('clientId' => CLIENT_ID, 'clientSecret' => CLIENT_SECRET, 'redirectUri' => REDIRECT_URI));
// set production url
$client->setApiUrl('//beta.360medical.fr/app_dev.php');
/**
 * Start your own logic
 */
$session = new Session();
$myStorage = new DatabaseConnection(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// sent by OAuth, you should know that
$state = $_GET['state'];
// personal state
$code = $_GET['code'];
// follow the OAuth protocol and get an access token and a refresh token
if ($client->authorizationCodeCaught()) {
    // make the next OAuth call to get those tokens (crendentials)
    $response = $client->getCredentials();
    if ($response->getCode() !== 200) {
        throw new \Exception(sprintf("An OAuth error occured: %s", $response->getErrorMessage()));
    }
    // now merge or create our user if it does not exist !
    // $appUser     = $myStorage->getUser($session->getUserId());