/
example-implementer.php
executable file
·60 lines (53 loc) · 1.33 KB
/
example-implementer.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
<?php
class Rotor_Controller_Auth {
/**
* Obtain a request token
*
* Endpoint: /auth/request_token
*/
public static function request_token() {
try {
$request = OAuthRequest::from_request();
$data = WPOAuthProvider::request_token($request);
header('Content-Type: application/x-www-form-urlencoded');
echo http_build_query($data, null, '&');
}
catch (OAuthException $e) {
throw new Exception($e->getMessage(), 401);
}
}
/**
* Request authorisation for the given token
*
* Endpoint: /auth/authorize
* @param string $oauth_token Request token
*/
public static function authorize($oauth_token) {
try {
$request = OAuthRequest::from_request();
$url = '/auth/authorize';
$data = WPOAuthProvider::authorize($request, $url);
header('Content-Type: text/plain');
echo http_build_query($data, null, '&');
}
catch (OAuthException $e) {
throw new Exception($e->getMessage(), 401);
}
}
/**
* Exchange the request token for an access token
*
* Endpoint: /auth/access_token
*/
public static function access_token() {
try {
$request = OAuthRequest::from_request();
$result = WPOAuthProvider::access_token($request);
header('Content-Type: application/x-www-form-urlencoded');
echo $result;
}
catch (OAuthException $e) {
throw new Exception($e->getMessage(), 401);
}
}
}