function setupConection($client_id, $client_secret) { Podio::setup($this->client_id, $this->client_secret); try { Podio::authenticate('app', array('app_id' => $this->app_id, 'app_token' => $this->app_token)); } catch (PodioError $e) { } }
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 header_wppo() { $podio_pass_var = get_option('wppo_podio_pass_var'); // Load Podio lib require_once dirname(__FILE__) . '/_/Podio/PodioAPI.php'; // Setup client $client_id = $podio_pass_var['client_id']; $client_secret = $podio_pass_var['client_secret']; Podio::setup($client_id, $client_secret); // Obtain access token using authorization code from the first step of the authentication flow // Podio::authenticate('authorization_code', array('code' => $_GET['code'], 'redirect_uri' => $redirect_uri)); // Alternatively you can supply a username and password directly. E.g.: // It wasn't there, so regenerate the data and save the transient $username = $podio_pass_var['user']; $password = $podio_pass_var['password']; try { Podio::authenticate('password', array('username' => $username, 'password' => $password)); // 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. } }
<?php require 'vendor/autoload.php'; require_once 'app_setting.inc.php'; use ZendService\LiveDocx\MailMerge; error_log("validate triggerd"); // Setup client Podio::setup($client_id, $client_secret); // Turn on debugging Podio::$debug = true; // Authenticate the app Podio::authenticate('app', array('app_id' => $app_id, 'app_token' => $app_token)); switch ($_POST['type']) { case 'hook.verify': // Validate the webhook PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code'])); case 'item.create': $item = PodioItem::get($_POST['item_id']); $temp_array = array(); foreach ($item->files as $fs) { $temp_array[] = $fs; if ($fs->mimetype == 'application/msword') { //Get file name withour ext $no_ext = substr($fs->name, 0, strpos($fs->name, '.')); //Upload file to our server $fl = PodioFile::get($fs->file_id); $fc = $fl->get_raw(); file_put_contents($upload_path . $fs->name, $fc); //Part with convert files from doc(x) to pdf $mailMerge = new MailMerge(); $mailMerge->setUsername($user)->setPassword($password)->setService(MailMerge::SERVICE_FREE);
// way to persist the Podio API authentication between page // loads. The goal to avoid having to re-authenticate each time // a page is refreshed. It is enabled by default. // If you open lib/PodioSession.php you can see how simple the // session manager is. It just has get, set and destroy methods. // You can use the Podio::is_authenticated() method to check if // there is a stored access token already present: Podio::setup(CLIENT_ID, CLIENT_SECRET); if (Podio::is_authenticated()) { // There is already authentication present. We can make API // calls without authenticating again: $item = PodioItem::get(YOUR_ITEM_ID); } else { // No authentication present. We have to authentication // before making API calls: Podio::authenticate('app', array('app_id' => YOUR_APP_ID, 'app_token' => YOUR_APP_TOKEN)); $item = PodioItem::get(YOUR_ITEM_ID); } // The downside of the built-in session manager is that it just // stores the access tokens in the $_SESSION. This means that you // will have to re-authenticate a user each time their close their browser // Often you will want to persist the access tokens for a longer period. // To do so you can implement your own session manager. All you need // is to create a class that implements the same get, set and destroy methods. // Then you can store the access tokens in your database or whereever. // When doing the client setup all you need to pass in the name of your session manager // class as an option and it will be used instead of the built-in one. // For example if your session manager class is called 'MySessionManager' Podio::setup(CLIENT_ID, CLIENT_SECRET, array('session_manager' => 'MySessionManager')); // If the built-in session manager is causing you trouble you can disable it. // This can be useful during development to make sure no stale access tokens are stored.
<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> </html>
if (Podio::is_authenticated()) { // Use Podio::is_authenticated() to check is there's already an active session. // If there is you can make API calls right away. print "You were already authenticated and no authentication is needed. Close and reopen your browser to start over.<br>"; $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>"; } elseif (!isset($_GET['code'])) { // If $_GET['code'] is not set it means we are not trying to authenticate. // In that case just display a link to start the serv flow $auth_url = htmlentities(Podio::authorize_url(REDIRECT_URI)); print "<a href='{$auth_url}'>Start authenticating</a>"; } else { // Otherwise try to authenticate using the code provided. // $_GET['error'] is set if there was a problem if (!isset($_GET['error'])) { Podio::authenticate('authorization_code', array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI)); $access_token = Podio::$oauth->access_token; print "You have been authenticated. Wee!<br>"; print "Your access token is {$access_token}<br><br>"; print "Hang onto this access token along with the refresh token (store them in a session or similar) so you don't have to re-authenticate for every request.<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>"; } else { print "There was a problem. The server said: {$_GET['error_description']}<br>"; } } ?> </body> </html>