-
Notifications
You must be signed in to change notification settings - Fork 5
/
OAuth1.php
106 lines (91 loc) · 2.26 KB
/
OAuth1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace drsdre\WordpressApi;
/**
* Allows authentication through Wordpress oAuth 1.
*
* In order to use Wordpress OAuth you must register your application in your Wordpress site with
* the WP REST API Oauth plugin.
*
* Example application configuration:
*
* ```php
* 'components' => [
* 'authClientCollection' => [
* 'class' => 'yii\authclient\Collection',
* 'clients' => [
* 'wordpress' => [
* 'class' => 'drsdre\WordpressApi\Auth',
* 'consumerKey' => 'wordpress_client_key',
* 'consumerSecret' => 'wordpress_client_secret',
* ],
* ],
* ]
* ...
* ]
* ```
*
* @see https://github.com/WP-API/OAuth1
* @see https://wordpress.org/plugins/rest-api-oauth1/
*
* @author Andre Schuurman <[email protected]>
*/
class OAuth1 extends \yii\authclient\OAuth1 {
/**
* @inheritdoc
*/
public $authUrl = 'oauth1/authorize';
/**
* @inheritdoc
*/
public $requestTokenUrl = 'oauth1/request';
/**
* @inheritdoc
*/
public $requestTokenMethod = 'POST';
/**
* @inheritdoc
*/
public $accessTokenUrl = 'oauth1/access';
/**
* @inheritdoc
*/
public $accessTokenMethod = 'POST';
/**
* @inheritdoc
*/
public $authorizationHeaderMethods = [ 'POST', 'PATCH', 'PUT', 'DELETE' ];
/**
* var $apiBaseUrl is Wordpress site url (json slug is auto added)
*/
public $apiBaseUrl;
/**
* @inheritdoc
*/
public function __construct( array $config ) {
parent::__construct( $config );
// Add apiBaseUrl to auth, requestToken and accessToken URL's
$this->authUrl = $this->apiBaseUrl . '/' . $this->authUrl;
$this->requestTokenUrl = $this->apiBaseUrl . '/' . $this->requestTokenUrl;
$this->accessTokenUrl = $this->apiBaseUrl . '/' . $this->accessTokenUrl;
// Set apiBaseUrl to Wordpress Rest API base slug
$this->apiBaseUrl = $this->apiBaseUrl . '/wp-json';
}
/**
* @inheritdoc
*/
protected function initUserAttributes() {
return $this->api( 'account/verify_credentials.json', 'GET', $this->attributeParams );
}
/**
* @inheritdoc
*/
protected function defaultName() {
return 'wordpress';
}
/**
* @inheritdoc
*/
protected function defaultTitle() {
return 'Wordpress';
}
}