Exemplo n.º 1
0
 public function testCreateAuthUrl()
 {
     $Client = new Client();
     $this->assertEquals('http://www.odnoklassniki.ru/oauth/authorize?client_id=&response_type=code&redirect_uri=&scope=', $Client->createAuthUrl([]));
     $this->assertEquals('http://www.odnoklassniki.ru/oauth/authorize?client_id=&response_type=code&redirect_uri=&scope=&layout=m', $Client->createAuthUrl([], true));
     $this->assertEquals('http://www.odnoklassniki.ru/oauth/authorize?client_id=&response_type=code&redirect_uri=&scope=VALUABLE ACCESS;SET STATUS;PHOTO CONTENT&layout=m', $Client->createAuthUrl([Client::SCOPE_VALUABLE_ACCESS, Client::SCOPE_SET_STATUS, Client::SCOPE_PHOTO_CONTENT], true));
     $Client->setClientId('clientIdentifier')->setRedirectUri('https://example.com/oauth2callback');
     $this->assertEquals('http://www.odnoklassniki.ru/oauth/authorize?client_id=clientIdentifier&response_type=code&redirect_uri=https://example.com/oauth2callback&scope=VALUABLE ACCESS;PHOTO CONTENT', $Client->createAuthUrl([Client::SCOPE_VALUABLE_ACCESS, Client::SCOPE_PHOTO_CONTENT]));
 }
Exemplo n.º 2
0
$clientId = '';
$clientSecret = '';
$redirectUri = '';
$refreshToken = '';
$Command = new CommandPosix();
$Command->appendHelpParameter('show help');
$Command->appendParameter(new Option('client', 'c', 'client id', Option::TYPE_STRING, true), function ($name, $value) use(&$clientId) {
    $clientId = $value;
});
$Command->appendParameter(new Option('redirect', 'r', 'redirect uri', Option::TYPE_STRING, true), function ($name, $value) use(&$redirectUri) {
    $redirectUri = $value;
});
$Command->appendParameter(new Option('token', 't', 'refresh token', Option::TYPE_STRING, true), function ($name, $value) use(&$refreshToken) {
    $refreshToken = $value;
});
$Command->appendParameter(new Option('secret', 's', 'client secret', Option::TYPE_STRING, true), function ($name, $value) use(&$clientSecret) {
    $clientSecret = $value;
});
try {
    $Command->parse(true);
    $Client = new Client();
    $Client->setClientId($clientId)->setClientSecret($clientSecret)->setRedirectUri($redirectUri);
    $Token = $Client->refresh($refreshToken);
    if ($Token instanceof Token) {
        printf("%s\n", (string) $Token);
    } else {
        var_dump($Token);
    }
} catch (RequiredOptionException $Ex) {
    $Command->displayHelp();
}
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * 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.
 *
 * Odnoklassniki authorization example
 * @author alxmsl
 * @date 8/12/13
 */
include '../vendor/autoload.php';
use alxmsl\Odnoklassniki\OAuth2\Client;
use alxmsl\Odnoklassniki\OAuth2\Response\Token;
// Create and initialize OAuth client
$Client = new Client();
$Client->setClientId(1234567890)->setClientSecret('C11eNt_SEcREt')->setRedirectUri('http://redirect.uri');
// Get authorization token instance by authoprization code
$Token = $Client->authorize('aUTH0R1zAt10N_c0dE');
print_r($Token);
// If success, refresh authorization token
if ($Token instanceof Token) {
    $Token = $Client->refresh('ReFRE5H_t0Ken');
    print_r($Token);
}
Exemplo n.º 4
0
<?php

/**
 * Copyright 2015 Alexey Maslov <*****@*****.**>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * 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.
 *
 * Get authorization code for Odnoklassniki OAuth
 * @author alxmsl
 * @date 8/12/13
 */
include '../vendor/autoload.php';
use alxmsl\Odnoklassniki\OAuth2\Client;
// Create and initialize OAuth client
$Client = new Client();
$Client->setClientId(1234567890)->setRedirectUri('http://redirect.uri');
// Get authorization url
$url = $Client->createAuthUrl([Client::SCOPE_VALUABLE_ACCESS, Client::SCOPE_SET_STATUS, Client::SCOPE_PHOTO_CONTENT], true);
printf("%s\n", $url);