public static function handleRedirectReturn($data = false) { if (!isset($data['state'])) { return "Please start the Dropbox authentication flow from the beginning."; } $connections = CASHSystem::getSystemSettings('system_connections'); if (!isset($connections['com.dropbox'])) { return 'Please add default Dropbox credentials.'; } $auth_client = DropboxSeed::getWebAuthClient($connections['com.dropbox']['redirect_uri']); try { list($token, $user_id) = $auth_client->finish($data); } catch (Exception $e) { $token = false; } if (!$token) { return "The Dropbox authentication flow failed - please try again."; } $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings($user_id . ' (Dropbox)', 'com.dropbox', array('access_token' => $token, 'user_id' => $user_id)); if (!$result) { $settings_for_user = $new_connection->getAllConnectionsforUser(); if (is_array($settings_for_user)) { foreach ($settings_for_user as $key => $connection_data) { if ($connection_data['name'] == $user_id . ' (Dropbox)') { $result = $connection_data['id']; break; } } } } if (isset($data['return_result_directly'])) { return $result; } else { if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/settings/connections/'); } } }
<?php $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $settings_types_data = $page_data_object->getConnectionTypes(); $settings_for_user = $page_data_object->getAllConnectionsforUser(); if ($request_parameters) { $settings_action = $request_parameters[0]; }
public static function handleRedirectReturn($data = false) { if (isset($data['code'])) { $connections = CASHSystem::getSystemSettings('system_connections'); if (isset($connections['com.google.drive'])) { $credentials = GoogleDriveSeed::exchangeCode($data['code'], $connections['com.google.drive']['client_id'], $connections['com.google.drive']['client_secret'], $connections['com.google.drive']['redirect_uri']); $user_info = GoogleDriveSeed::getUserInfo($credentials, $connections['com.google.drive']['client_id'], $connections['com.google.drive']['client_secret']); if ($user_info) { $email_address = $user_info['email']; $user_id = $user_info['id']; } else { $email_address = false; $user_id = false; } $credentials_array = json_decode($credentials, true); if (isset($credentials_array['refresh_token'])) { // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth // calls would only happen in the admin. If this changes we can f**k around with it later. $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings($email_address . ' (Google Drive)', 'com.google.drive', array('user_id' => $user_id, 'email_address' => $email_address, 'access_token' => $credentials, 'access_expires' => $credentials_array['created'] + $credentials_array['expires_in'], 'refresh_token' => $credentials_array['refresh_token'])); if (!$result) { $settings_for_user = $new_connection->getAllConnectionsforUser(); if (is_array($settings_for_user)) { foreach ($settings_for_user as $key => $connection_data) { if ($connection_data['name'] == $email_address . ' (Google Drive)') { $result = $connection_data['id']; break; } } } } if (isset($data['return_result_directly'])) { return $result; } else { if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/settings/connections/'); } } } else { return 'Could not find a refresh token from google'; } } else { return 'Please add default google drive app credentials.'; } } else { return 'There was an error. (session) Please try again.'; } }