|
18 | 18 | *
|
19 | 19 | * If you're already familiar with the process, you can skip the explanation below.
|
20 | 20 | *
|
21 |
| - * To get started with GitHub authentication, you need to create a new GitHub |
22 |
| - * application. |
| 21 | + * To get started with GitHub authentication, you need to create a new GitHub application. |
23 | 22 | *
|
24 | 23 | * First, navigate to https://github.com/settings/developers then click the Register
|
25 | 24 | * new application button at the top right of that page and fill in any required fields
|
26 | 25 | * such as the application name, description and website.
|
27 | 26 | *
|
28 | 27 | * Set the Authorization callback URL to https://path/to/hybridauth/examples/example_01.php.
|
29 |
| - * Understandably, you need to replace 'path/to/hybridauth' with the real path to this |
30 |
| - * script. |
| 28 | + * Understandably, you need to replace 'path/to/hybridauth' with the real path to this script. |
31 | 29 | *
|
32 |
| - * Note that Hybridauth provides an utility function that can generate the current page url for |
33 |
| - * you and can be used for the callback. Exemple: 'callback' => Hybridauth\HttpClient\Util::getCurrentUrl() |
| 30 | + * Note that Hybridauth provides an utility function that can generate the current page url for you |
| 31 | + * and can be used for the callback. Example: 'callback' => Hybridauth\HttpClient\Util::getCurrentUrl() |
34 | 32 | *
|
35 | 33 | * After configuring your GitHub application, simple replace 'your-app-id' and 'your-app-secret'
|
36 | 34 | * with your application credentials (Client ID and Client Secret).
|
|
46 | 44 | $config = [
|
47 | 45 | 'callback' => 'https://path/to/hybridauth/examples/example_01.php', // or Hybridauth\HttpClient\Util::getCurrentUrl()
|
48 | 46 |
|
49 |
| - 'keys' => ['id' => 'your-app-id', 'secret' => 'your-app-secret'], |
| 47 | + 'keys' => [ 'id' => 'your-app-id', 'secret' => 'your-app-secret' ], // Your Github application credentials |
50 | 48 |
|
51 |
| - 'scope' => 'user:email' |
| 49 | + /* optional : set scope |
| 50 | + 'scope' => 'user:email', */ |
52 | 51 |
|
53 | 52 | /* optional : set debug mode
|
54 |
| - // You can also set it to |
55 |
| - // - false To disable logging |
56 |
| - // - true To enable logging |
57 |
| - // - 'error' To log only error messages. Useful in production |
58 |
| - // - 'info' To log info and error messages (ignore debug messages] |
59 | 53 | 'debug_mode' => true,
|
60 |
| - // 'debug_mode' => 'info', |
61 |
| - // 'debug_mode' => 'error', |
62 |
| - // Path to file writable by the web server. Required if 'debug_mode' is not false |
| 54 | + // Path to file writeable by the web server. Required if 'debug_mode' is not false |
63 | 55 | 'debug_file' => __FILE__ . '.log', */
|
64 | 56 |
|
65 | 57 | /* optional : customize Curl settings
|
66 | 58 | // for more information on curl, refer to: http://www.php.net/manual/fr/function.curl-setopt.php
|
67 | 59 | 'curl_options' => [
|
68 | 60 | // setting custom certificates
|
69 |
| - // http://curl.haxx.se/docs/caextract.html |
70 | 61 | CURLOPT_SSL_VERIFYPEER => true,
|
71 | 62 | CURLOPT_CAINFO => '/path/to/your/certificate.crt',
|
72 | 63 |
|
73 |
| - // setting proxies |
74 |
| - # CURLOPT_PROXY => '*.*.*.*:*', |
| 64 | + // set a valid proxy ip address |
| 65 | + CURLOPT_PROXY => '*.*.*.*:*', |
75 | 66 |
|
76 |
| - // custom user agent |
77 |
| - # CURLOPT_USERAGENT => '', |
78 |
| -
|
79 |
| - // etc.. |
80 |
| - ], */ |
| 67 | + // set a custom user agent |
| 68 | + CURLOPT_USERAGENT => '' |
| 69 | + ] */ |
81 | 70 | ];
|
82 | 71 |
|
83 | 72 | /**
|
|
104 | 93 | /**
|
105 | 94 | * Step 5: Retrieve Users Profiles
|
106 | 95 | *
|
107 |
| - * |
| 96 | + * Calling getUserProfile returns an instance of class Hybridauth\User\Profile which contain the |
| 97 | + * connected user's profile in simple and standardized structure across all the social APIs supported |
| 98 | + * by HybridAuth. |
108 | 99 | */
|
109 | 100 |
|
110 | 101 | $userProfile = $github->getUserProfile();
|
|
120 | 111 | * As an example we list the authenticated user's public gists.
|
121 | 112 | */
|
122 | 113 |
|
123 |
| -$apiResponse = $github->apiRequest('gists/public'); |
| 114 | +$apiResponse = $github->apiRequest('gists'); |
124 | 115 |
|
125 | 116 | /**
|
126 |
| - * Step 6: Disconnecting from the Provider API |
| 117 | + * Step 6: Disconnect the adapter |
127 | 118 | *
|
128 | 119 | * This will erase the current user authentication data from session, and any further
|
129 | 120 | * attempt to communicate with Github API will result on an authorisation exception.
|
|
143 | 134 | * has erased the oauth access token used to sign http requests from the current
|
144 | 135 | * session, thus, any new request we now make will now throw an exception.
|
145 | 136 | *
|
146 |
| - * It's also important that you don't show Hybridauth exception's messages to the |
147 |
| - * user as they may include sensitive data, and that you use your own error messages |
148 |
| - * instead. |
| 137 | + * It's important that you don't show Hybridauth exception's messages to the end user as |
| 138 | + * they may include sensitive data, and that you use your own error messages instead. |
149 | 139 | */
|
150 | 140 |
|
151 | 141 | try {
|
152 | 142 | $github->getUserProfile();
|
153 | 143 | }
|
154 | 144 |
|
155 | 145 | /**
|
156 |
| -* Catch Curl Errors |
157 |
| -* |
158 |
| -* This kind of error may happen when: |
159 |
| -* - Internet or Network issues. |
160 |
| -* - Your server configuration is not setup correctly. |
161 |
| -* The full list of curl errors that may happen can be found at http://curl.haxx.se/libcurl/c/libcurl-errors.html |
162 |
| -*/ |
| 146 | + * Catch Curl Errors |
| 147 | + * |
| 148 | + * This kind of error may happen in case of: |
| 149 | + * - Internet or Network issues. |
| 150 | + * - Your server configuration is not setup correctly. |
| 151 | + * |
| 152 | + * The full list of curl errors that may happen can be found at http://curl.haxx.se/libcurl/c/libcurl-errors.html |
| 153 | + */ |
| 154 | + |
163 | 155 | catch (Hybridauth\Exception\HttpClientFailureException $e) {
|
164 | 156 | echo 'Curl text error message : '.$github->getHttpClient()->getResponseClientError();
|
165 | 157 | }
|
166 | 158 |
|
167 | 159 | /**
|
168 |
| -* Catch API Requests Errors |
169 |
| -* |
170 |
| -* This usually happens when requesting a: |
171 |
| -* - Wrong URI or a mal-formatted http request. |
172 |
| -* - Protected resource without providing a valid access token. |
173 |
| -*/ |
| 160 | + * Catch API Requests Errors |
| 161 | + * |
| 162 | + * This usually happens when requesting a: |
| 163 | + * - Wrong URI or a mal-formatted http request. |
| 164 | + * - Protected resource without providing a valid access token. |
| 165 | + */ |
| 166 | + |
174 | 167 | catch (Hybridauth\Exception\HttpRequestFailedException $e) {
|
175 | 168 | echo 'Raw API Response: '.$github->getHttpClient()->getResponseBody();
|
176 | 169 | }
|
177 | 170 |
|
178 | 171 | /**
|
179 |
| -* I catch everything else |
180 |
| -*/ |
| 172 | + * Base PHP's exception that catches everything [else] |
| 173 | + */ |
| 174 | + |
181 | 175 | catch (\Exception $e) {
|
182 | 176 | echo 'Oops! We ran into an unknown issue: '.$e->getMessage();
|
183 | 177 | }
|
0 commit comments