@@ -17,25 +17,28 @@ public function isRedirected() {
17
17
return isset ($ _GET ['code ' ]);
18
18
}
19
19
20
- public function getCustomInformation ($ endpoint, $ forceRefresh = false ) {
21
- return $ this ->getInformation ($ forceRefresh , $ endpoint );
20
+ public function getCustomInformation ($ endpoint ) {
21
+ return $ this ->getInformation ($ endpoint );
22
22
}
23
23
24
- public function getUserInformation ($ forceRefresh = false ) {
25
- return $ this ->getInformation ($ forceRefresh , 'users/@me ' );
24
+ public function getUserInformation () {
25
+ return $ this ->getInformation ('users/@me ' );
26
26
}
27
27
28
- public function getConnectionsInformation ($ forceRefresh = false ) {
29
- return $ this ->getInformation ($ forceRefresh , 'users/@me/connections ' );
28
+ public function getConnectionsInformation () {
29
+ return $ this ->getInformation ('users/@me/connections ' );
30
30
}
31
31
32
- public function getGuildsInformation ($ forceRefresh = false ) {
33
- return $ this ->getInformation ($ forceRefresh , 'users/@me/guilds ' );
32
+ public function getGuildsInformation () {
33
+ return $ this ->getInformation ('users/@me/guilds ' );
34
34
}
35
35
36
- private function getInformation ($ forceRefresh , $ endpoint ) {
37
- if ($ forceRefresh === true || $ this ->_accessToken === null ) {
38
- $ this ->loadToken ();
36
+ private function getInformation ($ endpoint ) {
37
+ if ($ this ->_accessToken === null ) {
38
+ $ response = $ this ->loadToken ();
39
+ if ($ response !== true ) {
40
+ return ["code " => 0 , "message " => $ response ];
41
+ }
39
42
}
40
43
$ curl = curl_init ('https://discordapp.com/api/v6/ ' . $ endpoint );
41
44
curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , "false " );
@@ -47,10 +50,10 @@ private function getInformation($forceRefresh, $endpoint) {
47
50
return $ response ;
48
51
}
49
52
50
- private function loadToken () {
53
+ public function loadToken () {
51
54
if (empty ($ _GET ['state ' ]) || ($ _GET ['state ' ] !== $ _SESSION ['oauth2state ' ])) {
52
55
unset($ _SESSION ['oauth2state ' ]);
53
- throw new Exception ( 'Invalid state ' ) ;
56
+ return 'Invalid state ' ;
54
57
}
55
58
$ curl = curl_init ();
56
59
curl_setopt_array ($ curl , array (
@@ -59,10 +62,13 @@ private function loadToken() {
59
62
CURLOPT_POSTFIELDS => "client_id= " . $ this ->_clientId . "&client_secret= " . $ this ->_secret . "&grant_type=authorization_code&code= " . $ _GET ['code ' ] . "&redirect_uri= " . urlencode ($ this ->_redirectUrl ),
60
63
CURLOPT_RETURNTRANSFER => "false "
61
64
));
62
- $ response = curl_exec ($ curl );
63
- $ this ->_accessToken = json_decode ($ response , true )['access_token ' ];
65
+ $ response = json_decode (curl_exec ($ curl ), true );
66
+ if (array_key_exists ('error_description ' , $ response )) {
67
+ return $ response ['error_description ' ];
68
+ }
69
+ $ this ->_accessToken = $ response ['access_token ' ];
64
70
curl_close ($ curl );
65
- return $ response ;
71
+ return true ;
66
72
}
67
73
68
74
private static function generateToken () {
0 commit comments