Beispiel #1
0
<?php

use XeroPHP\Application\PublicApplication;
use XeroPHP\Remote\Request;
use XeroPHP\Remote\URL;
// Start a session for the oauth session storage
session_start();
//These are the minimum settings - for more options, refer to examples/config.php
$config = array('oauth' => array('callback' => 'http://localhost/', 'consumer_key' => 'k', 'consumer_secret' => 's'), 'curl' => array(CURLOPT_CAINFO => __DIR__ . '/certs/ca-bundle.crt'));
$xero = new PublicApplication($config);
//if no session or if it is expired
if (null === ($oauth_session = getOAuthSession())) {
    $url = new URL($xero, URL::OAUTH_REQUEST_TOKEN);
    $request = new Request($xero, $url);
    //Here's where you'll see if your keys are valid.  You can catch a BadRequestException.
    try {
        $request->send();
    } catch (Exception $e) {
        print_r($e);
        if ($request->getResponse()) {
            print_r($request->getResponse()->getOAuthResponse());
        }
    }
    $oauth_response = $request->getResponse()->getOAuthResponse();
    setOAuthSession($oauth_response['oauth_token'], $oauth_response['oauth_token_secret']);
    printf('<a href="%s">Click here to Authorize</a>', $xero->getAuthorizeURL($oauth_response['oauth_token']));
    exit;
} else {
    $xero->getOAuthClient()->setToken($oauth_session['token'])->setTokenSecret($oauth_session['token_secret']);
    if (isset($_REQUEST['oauth_verifier'])) {
        $xero->getOAuthClient()->setVerifier($_REQUEST['oauth_verifier']);
Beispiel #2
0
<?php

use XeroPHP\Application\PartnerApplication;
use XeroPHP\Remote\Request;
use XeroPHP\Remote\URL;
// Start a session for the oauth session storage
session_start();
//These are the minimum settings - for more options, refer to examples/config.php
$config = array('oauth' => array('callback' => 'http://localhost/', 'consumer_key' => 'k', 'consumer_secret' => 's', 'rsa_private_key' => 'file://certs/privatekey.pem'), 'curl' => array(CURLOPT_CAINFO => 'certs/ca-bundle.crt', CURLOPT_SSLCERT => 'certs/entrust-cert.pem', CURLOPT_SSLKEYPASSWD => '1234', CURLOPT_SSLKEY => 'certs/entrust-private.pem'));
$xero = new PartnerApplication($config);
$oauth_session = getOAuthSession();
// If no session found
if ($oauth_session === null) {
    $url = new URL($xero, URL::OAUTH_REQUEST_TOKEN);
    $request = new Request($xero, $url);
    //Here's where you'll see if your keys are valid.  You can catch a BadRequestException.
    try {
        $request->send();
    } catch (Exception $e) {
        echo $e->getCode();
        print_r($request->getResponse()->getOAuthResponse());
    }
    $oauth_response = $request->getResponse()->getOAuthResponse();
    setOAuthSession($oauth_response['oauth_token'], $oauth_response['oauth_token_secret']);
    printf('<a href="%s?oauth_token=%s">Click here to Authorize</a>', $xero->getAuthorizeURL(), $oauth_response['oauth_token']);
    exit;
} elseif (isset($oauth_session['session_handle']) && !isset($oauth_session['expires'])) {
    // If session is expired refresh the token
    $url = new URL($xero, URL::OAUTH_ACCESS_TOKEN);
    $request = new Request($xero, $url);
    $request->setParameter('oauth_token', $oauth_session['token']);