function check_config() { global $config; Podio::$debug = true; try { Podio::setup($config['podioClientId'], $config['podioClientSecret']); } catch (PodioError $e) { show_error("Podio Authentication Failed. Please check the API key and user details."); return false; } try { Podio::authenticate('password', array('username' => $config['podioUser'], 'password' => $config['podioPassword'])); } catch (PodioError $e) { show_error("Podio Authentication Failed. Please check the API key and user details."); return false; } if (!Podio::is_authenticated()) { show_error("Podio Authentication Failed. Please check the API key and user details."); return false; } return true; }
function authorize() { Podio::setup(CLIENT_ID, CLIENT_SECRET, array("session_manager" => "PodioSession")); if (Podio::is_authenticated()) { echo "already logged in"; } else { try { Podio::authenticate_with_password('*****@*****.**', '1Animation2'); // Authentication was a success, now you can start making API calls. } catch (PodioError $e) { // Something went wrong. Examine $e->body['error_description'] for a description of the error. } } }
?> <html> <head> <title>Username and Password authentication example</title> </head> <body> <?php // Include the config file and the Podio library require_once 'config.php'; require_once '../PodioAPI.php'; // Setup the API client reference. Client ID and Client Secrets are defined // as constants in config.php Podio::setup(CLIENT_ID, CLIENT_SECRET); // Use Podio::is_authenticated() to check is there's already an active session. // If there is you can make API calls right away. if (!Podio::is_authenticated()) { // Authenticate using your username and password. Both are defined as constants // in config.php Podio::authenticate('password', array('username' => USERNAME, 'password' => PASSWORD)); print "You have been authenticated. Wee!<br>"; $access_token = Podio::$oauth->access_token; print "Your access token is {$access_token}<br><br>"; print "The access token is automatically saved in a session for your convenience.<br><br>"; } else { print "You were already authenticated and no authentication happened. Close and reopen your browser to start over.<br><br>"; } // Now you can start making API calls. E.g. get your user status $status = PodioUserStatus::get(); print "Your user id is <b>{$status->user->id}</b> and you have <b>{$status->inbox_new}</b> unread messages in your inbox.<br><br>"; ?> </body>
if ($controller->validate_config($config)) { switch ($config['env']) { case 'local': define("REDIRECT_URI", 'http://localhost/podio_app/'); break; case 'development': define("REDIRECT_URI", 'http://podio-app.arsen-sargsyan.info/'); break; } $controller->init_podio($config); if (!isset($_GET['code']) && !Podio::is_authenticated()) { // User is not being reidrected and does not have an active session // We just display a link to the authentication page on podio.com $auth_url = htmlentities(Podio::authorize_url(REDIRECT_URI)); print "<a href='{$auth_url}'>Start authenticating</a>"; } elseif (Podio::is_authenticated()) { // User already has an active session. You can make API calls here: print "You were already authenticated and no authentication is needed."; } elseif (isset($_GET['code'])) { // If there was a problem $_GET['error'] is set: if (isset($_GET['error'])) { print "There was a problem. The server said: {$_GET['error_description']}"; } else { // Finalize authentication. Note that we must pass the REDIRECT_URI again. Podio::authenticate_with_authorization_code($_GET['code'], REDIRECT_URI); print "You have been authenticated. Try to send an email with attached word document!"; } } } else { echo 'Error occured! <br>'; foreach ($controller->config_errors as $error_mgs) {