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])); }
$clientId = $value; }); $Command->appendParameter(new Option('redirect', 'r', 'redirect uri', Option::TYPE_STRING), function ($name, $value) use(&$redirectUri) { $redirectUri = $value; }); $Command->appendParameter(new Option('scopes', 's', 'grant scopes', Option::TYPE_STRING), function ($name, $value) use(&$scopes) { $scopes = explode(',', $value); }); $Command->appendParameter(new Option('secret', 'e', '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); if (!empty($code)) { // Get authorization token for access application $Token = $Client->authorize($code); if ($Token instanceof Token) { printf("%s\n", (string) $Token); } else { var_dump($Token); } } else { // Get authorization uri $uri = $Client->createAuthUrl($scopes, true); printf("%s\n", $uri); } } catch (RequiredOptionException $Ex) { $Command->displayHelp(); }
<?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);