-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.php
57 lines (44 loc) · 1.65 KB
/
config.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
<?php
class gitsyllabus_oauth {
const OAUTH_URL = 'https://github.com/login/oauth/';
function __construct($client_id, $client_secret) {
//create oauth object and store developer key
$this->client_id = $client_id;
$this->client_secret = $client_secret;
}
function oauth_init() {
$args = array(
'client_id' => $client_id,
'state' => $state,
'status' => 302
);
$response = wp_remote_get( wp_redirect( ( OAUTH_URL . 'authorize' ), $args) );
if ( is_wp_error( $response ) ) {
echo 'oauth init failed';
}
else {
//where to parse out code response?
// $this->$oauth_code = $response
}
}
function oauth_validate($oauth_code) {
$args = array(
'body' => array(
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
'code' => $oauth_code
),
'headers' => array( 'Accept' => 'application/json')
);
$response = wp_remote_post( gitsyllabus_oauth::OAUTH_URL . 'access_token', $args );
if ( is_wp_error( $response ) || $response['response']['code'] >= 400 ) {
echo '<div class="error"><p>OAuth validation failed</p></div>';
return "";
}
else {
$body = json_decode($response['body']);
return $body->access_token;
}
}
}
?>