Exemple #1
0
 public function testSetAuthToken()
 {
     $rtm = new Rtm();
     $rtm->setAuthToken('e245k63469bdfg8dfg034rwfsdf');
     $this->assertEquals('e245k63469bdfg8dfg034rwfsdf', $rtm->getAuthToken());
     $rtm = new Rtm(array('authToken' => 'e245k63469bdfg8dfg034rwfsdf'));
     $this->assertEquals('e245k63469bdfg8dfg034rwfsdf', $rtm->getAuthToken());
 }
Exemple #2
0
$rtm->setSecret(SECRET);
$rtm->setAuthToken(isset($_SESSION['RTM_AUTH_TOKEN']) ? $_SESSION['RTM_AUTH_TOKEN'] : null);
try {
    // Check authentication token
    $rtm->getService(Rtm::SERVICE_AUTH)->checkToken();
    // Successfully authenticated, redirect to app
    header('Location: index.php');
} catch (Exception $e) {
    // Authentication request is taking place?
    if (isset($_GET['frob'])) {
        try {
            // Set the frob parameter
            $rtm->setFrob($_GET['frob']);
            // Call the getToken method, to acquire the token
            $response = $rtm->getService(Rtm::SERVICE_AUTH)->getToken();
            // Save token in Rtm object
            $rtm->setAuthToken($response->getToken());
            // Save token in session
            $_SESSION['RTM_AUTH_TOKEN'] = $rtm->getAuthToken();
            // Check authentication token
            $rtm->getService(Rtm::SERVICE_AUTH)->checkToken();
            // Authentication successful, redirect back to auth script to check again the token
            header('Location: rtm.php');
        } catch (Exception $e) {
            echo 'Authentication failed...';
        }
    } else {
        // No permissions, acquire it
        header('Location: ' . $rtm->getAuthUrl(Rtm::AUTH_TYPE_READ));
    }
}