├── .gitignore ├── Odnoklassniki.php ├── README.md └── composer.json /.gitignore: -------------------------------------------------------------------------------- 1 | # phpstorm project files 2 | .idea 3 | 4 | # netbeans project files 5 | nbproject 6 | 7 | # zend studio for eclipse project files 8 | .buildpath 9 | .project 10 | .settings 11 | 12 | # windows thumbnail cache 13 | Thumbs.db 14 | 15 | # composer vendor dir 16 | /vendor 17 | 18 | # composer itself is not needed 19 | composer.phar 20 | composer.lock 21 | 22 | # Mac DS_Store Files 23 | .DS_Store 24 | -------------------------------------------------------------------------------- /Odnoklassniki.php: -------------------------------------------------------------------------------- 1 | attributeNames); 51 | $params['access_token'] = $this->accessToken->getToken(); 52 | $params['application_key'] = $this->applicationKey; 53 | $params['sig'] = $this->sig($params, $params['access_token'], $this->clientSecret); 54 | return $this->api('api/users/getCurrentUser', 'GET', $params); 55 | } 56 | 57 | /** 58 | * @inheritdoc 59 | */ 60 | protected function apiInternal($accessToken, $url, $method, array $params, array $headers) 61 | { 62 | $params['access_token'] = $accessToken->getToken(); 63 | $params['application_key'] = $this->applicationKey; 64 | $params['method'] = str_replace('/', '.', str_replace('api/', '', $url)); 65 | $params['sig'] = $this->sig($params, $params['access_token'], $this->clientSecret); 66 | 67 | return $this->sendRequest($method, $url, $params, $headers); 68 | } 69 | 70 | /** 71 | * Generates a signature 72 | * @param $vars array 73 | * @param $accessToken string 74 | * @param $secret string 75 | * @return string 76 | */ 77 | protected function sig($vars, $accessToken, $secret) 78 | { 79 | ksort($vars); 80 | $params = ''; 81 | foreach ($vars as $key => $value) { 82 | if (in_array($key, ['sig', 'access_token'])) { 83 | continue; 84 | } 85 | $params .= "$key=$value"; 86 | } 87 | return md5($params . md5($accessToken . $secret)); 88 | } 89 | 90 | /** 91 | * @inheritdoc 92 | */ 93 | protected function defaultName() 94 | { 95 | return 'odnoklassniki'; 96 | } 97 | 98 | /** 99 | * @inheritdoc 100 | */ 101 | protected function defaultTitle() 102 | { 103 | return 'Odnoklassniki'; 104 | } 105 | 106 | /** 107 | * @inheritdoc 108 | */ 109 | protected function defaultReturnUrl() 110 | { 111 | $params = $_GET; 112 | unset($params['code']); 113 | unset($params['state']); 114 | unset($params['permissions_granted']); 115 | $params[0] = \Yii::$app->controller->getRoute(); 116 | 117 | return \Yii::$app->getUrlManager()->createAbsoluteUrl($params); 118 | } 119 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # yii2-odnoklassiniki-authclient 2 | 3 | This extension adds Odnoklassniki OAuth2 supporting for [yii2-authclient](https://github.com/yiisoft/yii2-authclient). 4 | 5 | ## Installation 6 | 7 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 8 | 9 | Either run 10 | 11 | ``` 12 | php composer.phar require --prefer-dist kotchuprik/yii2-odnoklassniki-authclient "*" 13 | ``` 14 | 15 | or add 16 | 17 | ```json 18 | "kotchuprik/yii2-odnoklassniki-authclient": "*" 19 | ``` 20 | 21 | to the `require` section of your composer.json. 22 | 23 | ## Usage 24 | 25 | You must read the yii2-authclient [docs](https://github.com/yiisoft/yii2/blob/master/docs/guide/security-auth-clients.md) 26 | 27 | Register your application [in Odnoklassniki](https://apiok.ru/wiki/pages/viewpage.action?pageId=42476486) 28 | 29 | and add the Odnoklassniki client to your auth clients. 30 | 31 | ```php 32 | 'components' => [ 33 | 'authClientCollection' => [ 34 | 'class' => 'yii\authclient\Collection', 35 | 'clients' => [ 36 | 'odnoklassniki' => [ 37 | 'class' => 'kotchuprik\authclient\Odnoklassniki', 38 | 'applicationKey' => 'odnoklassniki_app_public_key', 39 | 'clientId' => 'odnoklassniki_app_id', 40 | 'clientSecret' => 'odnoklassniki_client_secret', 41 | ], 42 | ], 43 | // other clients 44 | ], 45 | ], 46 | // ... 47 | ] 48 | ``` 49 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kotchuprik/yii2-odnoklassniki-authclient", 3 | "require": { 4 | "yiisoft/yii2-authclient": "~2.0@dev" 5 | }, 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Constantin Chuprik", 10 | "email": "constantinchuprik@gmail.com" 11 | } 12 | ], 13 | "autoload": { 14 | "psr-4": { 15 | "kotchuprik\\authclient\\": "" 16 | } 17 | } 18 | } 19 | --------------------------------------------------------------------------------