Пример #1
0
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Google web server authorization example
 * @author alxmsl
 * @date 1/24/13
 */
include '../vendor/autoload.php';
use alxmsl\Google\OAuth2\Response\Token;
use alxmsl\Google\OAuth2\WebServerApplication;
// Define client identification
const CLIENT_ID = 'my-client@id', CLIENT_SECRET = 'clientsecret';
// Create new client
$Client = new WebServerApplication();
$Client->setClientId(CLIENT_ID)->setClientSecret(CLIENT_SECRET);
// Get access token
$Token = $Client->authorizeByCode($code);
if ($Token instanceof Token) {
    var_dump($Token);
    // Get refresh token
    $Refreshed = $Client->refresh($Token->getRefreshToken());
    var_dump($Refreshed);
    $revoked = $Client->revoke($Token->getAccessToken());
    if ($revoked) {
        printf('token %s was revoke', $Token->getAccessToken());
    } else {
        printf('error on revoke token %s', $Token->getAccessToken());
    }
} else {
    var_dump($Token);
}
Пример #2
0
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Script for Google API access token refreshing
 * @author alxmsl
 */
include __DIR__ . '/../vendor/autoload.php';
use alxmsl\Cli\CommandPosix;
use alxmsl\Cli\Exception\RequiredOptionException;
use alxmsl\Cli\Option;
use alxmsl\Google\OAuth2\WebServerApplication;
$token = '';
$Command = new CommandPosix();
$Command->appendHelpParameter('show help');
$Command->appendParameter(new Option('token', 't', 'revoked token', Option::TYPE_STRING, true), function ($name, $value) use(&$token) {
    $token = $value;
});
try {
    $Command->parse(true);
    $Client = new WebServerApplication();
    $revoked = $Client->revoke($token);
    if ($revoked) {
        printf("token %s revoked\n", $token);
    } else {
        printf("token %s was not revoke\n", $token);
    }
} catch (RequiredOptionException $Ex) {
    $Command->displayHelp();
}