1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Example of making API calls for the Redmine service |
||
5 | * Developed against https://github.com/suer/redmine_oauth_provider |
||
6 | * To create oauth credentials read the plugin documentation from |
||
7 | * redmine_oauth_provider. |
||
8 | * |
||
9 | * @author Patrick Herzberg <[email protected]> |
||
10 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
||
11 | * |
||
12 | * Example based on the yahoo example |
||
13 | */ |
||
14 | |||
15 | /** |
||
16 | * Bootstrap the example. |
||
17 | */ |
||
18 | require_once __DIR__ . '/bootstrap.php'; |
||
19 | |||
20 | use OAuth\Common\Consumer\Credentials; |
||
21 | use OAuth\Common\Http\Uri\Uri; |
||
22 | use OAuth\Common\Storage\Session; |
||
23 | |||
24 | // Session storage |
||
25 | $storage = new Session(); |
||
26 | |||
27 | // Setup the credentials for the requests |
||
28 | $credentials = new Credentials( |
||
29 | $servicesCredentials['redmine']['key'], |
||
30 | $servicesCredentials['redmine']['secret'], |
||
31 | $currentUri->getAbsoluteUri() |
||
32 | ); |
||
33 | |||
34 | // Instantiate the Redmine service using the credentials, http client, storage mechanism for the token and adding the base uri of the oauth provider |
||
35 | $redmineService = $serviceFactory->createService('Redmine', $credentials, $storage, [], new Uri('https://redmine.example.dev/oauth/')); |
||
36 | |||
37 | if (!empty($_GET['oauth_token'])) { |
||
38 | $token = $storage->retrieveAccessToken('Redmine'); |
||
39 | |||
40 | // This was a callback request from Redmine, get the token |
||
41 | $redmineService->requestAccessToken( |
||
42 | $_GET['oauth_token'], |
||
43 | $_GET['oauth_verifier'], |
||
44 | $token->getRequestTokenSecret() |
||
45 | ); |
||
46 | |||
47 | // Send a request now that we have access token |
||
48 | $result = json_decode($redmineService->request('user_info.json')); |
||
49 | |||
50 | echo 'result: <pre>' . print_r($result, true) . '</pre>'; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
51 | } elseif (!empty($_GET['go']) && $_GET['go'] === 'go') { |
||
52 | // extra request needed for oauth1 to request a request token :-) |
||
53 | $token = $redmineService->requestRequestToken(); |
||
54 | |||
55 | $url = $redmineService->getAuthorizationUri(['oauth_token' => $token->getRequestToken()]); |
||
56 | header('Location: ' . $url); |
||
57 | } else { |
||
58 | $url = 'http://example.dev/' . '?go=go'; |
||
59 | echo "<a href='$url'>Login with Redmine!</a>"; |
||
60 | } |
||
61 |