|
9 | 9 | // Include settings
|
10 | 10 | require_once('config.ini.php');
|
11 | 11 |
|
12 |
| - // Generate GET/POST URLs |
13 |
| - if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') { |
14 |
| - $protocol = 'http://'; |
15 |
| - } else { |
16 |
| - $protocol = 'https://'; |
17 |
| - } |
18 |
| - $base_url = $protocol . $_SERVER['SERVER_NAME'] . dirname($_SERVER['PHP_SELF']); |
19 |
| - if ($_SERVER["SERVER_PORT"] != "80") { |
20 |
| - $base_url = $protocol . $_SERVER['SERVER_NAME'] . ":" . $_SERVER["SERVER_PORT"] . dirname($_SERVER['PHP_SELF']); |
21 |
| - } |
22 |
| - $loginUrl = $subFolder. "/v2/oauth2/authorize?api_key=".urlencode($api_key); |
| 12 | + $self = dirname($_SERVER['PHP_SELF']); |
23 | 13 |
|
24 |
| - // This will be the redirect targets for generating bearer tokens via GET (POST contains this info in the header) |
25 |
| - $authGrantUrl = $loginUrl."&redirect_uri=".urlencode($base_url."/endpoints/authcode_endpoint.php")."&response_type=code"; |
26 |
| - $implicitGrantUrl = $loginUrl."&redirect_uri=".urlencode($base_url."/endpoints/implicitgrant_endpoint.php")."&response_type=token"; |
| 14 | + $apiDir = $ilias_url . "/Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/REST"; |
| 15 | + $authUrl = $apiDir . "/api.php/v2/oauth2/authorize"; |
| 16 | + $tokenUrl = $apiDir . "/api.php/v2/oauth2/token"; |
| 17 | + |
| 18 | + $authGrantRedirect = $self . "/endpoints/authcode_endpoint.php"; |
| 19 | + $implicitGrantRedirect = $self . "/endpoints/implicitgrant_endpoint.php"; |
| 20 | + |
| 21 | + $loginUrl = $authUrl . "?api_key=" . urlencode($api_key); |
| 22 | + $authGrantUrl = $loginUrl . "&response_type=code&redirect_uri=" . urlencode($authGrantRedirect); |
| 23 | + $implicitGrantUrl = $loginUrl . "&response_type=token&redirect_uri=" . urlencode($implicitGrantRedirect); |
27 | 24 | ?>
|
28 | 25 | <h3>Initiating one of the following OAuth2 Grant Mechanism via a GET Request:</h3>
|
29 | 26 | <ul>
|
|
33 | 30 | <h3>Initiating one of the following OAuth2 Grant Mechanism via a POST Request:</h3>
|
34 | 31 | <ul>
|
35 | 32 | <li>
|
36 |
| - <form method="POST" action="<?php echo $subFolder;?>/v2/oauth2/authorize"> |
| 33 | + <form method="POST" action="<?php echo $authUrl; ?>"> |
37 | 34 | <input type="hidden" name="api_key" value="<?php echo $api_key; ?>" />
|
38 | 35 | <input type="hidden" name="response_type" value="code" />
|
39 |
| - <input type="hidden" name="redirect_uri" value="<?php echo $base_url."/endpoints/authcode_endpoint.php";?>" /> |
| 36 | + <input type="hidden" name="redirect_uri" value="<?php echo $authGrantRedirect; ?>" /> |
40 | 37 | <input type="submit" value="Authorization Code Grant" />
|
41 | 38 | </form>
|
42 | 39 | </li>
|
43 | 40 | <li>
|
44 |
| - <form method="POST" action="<?php echo $subFolder;?>/v2/oauth2/authorize"> |
| 41 | + <form method="POST" action="<?php echo $authUrl; ?>"> |
45 | 42 | <input type="hidden" name="api_key" value="<?php echo $api_key; ?>" />
|
46 | 43 | <input type="hidden" name="response_type" value="token" />
|
47 |
| - <input type="hidden" name="redirect_uri" value="<?php echo $base_url."/endpoints/implicitgrant_endpoint.php"; ?>" /> |
| 44 | + <input type="hidden" name="redirect_uri" value="<?php echo $implicitGrantRedirect; ?>" /> |
48 | 45 | <input type="submit" value="Implicit Grant" />
|
49 | 46 | </form>
|
50 | 47 | </li>
|
51 | 48 | <li>
|
52 |
| - <form method="POST" action="<?php echo $subFolder;?>/v2/oauth2/token"> |
| 49 | + <form method="POST" action="<?php echo $tokenUrl; ?>"> |
53 | 50 | <input type="hidden" name="grant_type" value="client_credentials" />
|
54 | 51 | <input type="hidden" name="scope" value="" />
|
55 | 52 | <input type="hidden" name="api_key" value="<?php echo $api_key; ?>" />
|
|
58 | 55 | </form>
|
59 | 56 | </li>
|
60 | 57 | <li>
|
61 |
| - <form method="POST" action="<?php echo $subFolder;?>/v2/oauth2/token"> |
| 58 | + <form method="POST" action="<?php echo $tokenUrl;?>"> |
62 | 59 | <div>
|
63 | 60 | <input type="hidden" name="grant_type" value="password" />
|
64 | 61 | <input type="hidden" name="scope" value="" />
|
|
0 commit comments