Exemplo n.º 1
0
 public function testProperGetAuthUrl()
 {
     $rtm = new Rtm();
     $rtm->setApiKey('dfgdfgsdgsgsdfgdfg');
     $rtm->setSecret('gd34tdvxvdfvdfgvdd');
     $url = $rtm->getAuthUrl(Rtm::AUTH_TYPE_WRITE);
     $this->assertEquals(Rtm::URL_AUTH, substr($url, 0, strlen(Rtm::URL_AUTH)));
     $this->assertRegExp('/api_key=dfgdfgsdgsgsdfgdfg&perms=write&api_sig=\\w{32}$/', parse_url($url, PHP_URL_QUERY));
 }
Exemplo n.º 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));
    }
}