Instantly share code, notes, and snippets.

anonymous /index
Created Aug 28, 2015

Embed
What would you like to do?
<html><head></head><body>
<?php
session_start('PodioSession');
require_once './PodioAPI.php';
require_once './session.php';
define("REDIRECT_URI", 'http://localhost/jpodio/');
define("CLIENT_ID", 'podioapitest-musmij');
define("CLIENT_SECRET", 'Y0GXKBi7WgEep1IcrJ5GNJ6r8Utv7CWuURCc0JwOw3QZpGUwnTrbUBGoRkGQOZXw');
Podio::setup(CLIENT_ID, CLIENT_SECRET, array("session_manager" => "PodioBrowserSession"));
if (Podio::is_authenticated() || isset($_GET['code'])) {
print "Authenticated! <br /><br>";
Podio::authenticate_with_authorization_code($_GET['code'], REDIRECT_URI);
//Get all organizations
$orgdata = PodioOrganization::get_all();
foreach ($orgdata as $org => $orgv){
print "{$orgdata[$org]->name} <br />";
foreach ($orgdata[$org]->spaces as $keyspaces => $works){print "--{$orgdata[$org]->spaces[$keyspaces]->name} <br />";} print "<br><br>";
}
}
else {
$auth_url = rawurldecode(Podio::authorize_url(REDIRECT_URI));
// Podio::authorize_url prepends 'https://podio.com/oauth/authorize?client_id=podioapitest-bh9oo0&redirect_uri='
print "<a href='{$auth_url}'>Login with Podio Account</a>";
}
?>
</body></html>
<?php
class PodioBrowserSession {
/**
* For sessions to work they must be started. We make sure to start
* sessions whenever a new object is created.
*/
public function __construct() {
if(!session_id()) {
session_start();
}
}
/**
* Get oauth object from session, if present. We ignore $auth_type since
* it doesn't work with server-side authentication.
*/
public function get($auth_type = null) {
// Check if we have a stored session
if (!empty($_SESSION['podio-php-session'])) {
// We have a session, create new PodioOauth object and return it
return new PodioOAuth(
$_SESSION['podio-php-session']['access_token'],
$_SESSION['podio-php-session']['refresh_token'],
$_SESSION['podio-php-session']['expires_in'],
$_SESSION['podio-php-session']['ref']
);
}
// Else return an empty object
return new PodioOAuth();
}
/**
* Store the oauth object in the session. We ignore $auth_type since
* it doesn't work with server-side authentication.
*/
public function set($oauth, $auth_type = null) {
// Save all properties of the oauth object in a session
$_SESSION['podio-php-session'] = array(
'access_token' => $oauth->access_token,
'refresh_token' => $oauth->refresh_token,
'expires_in' => $oauth->expires_in,
'ref' => $oauth->ref,
);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment