|
1 | 1 | <?php |
2 | 2 |
|
3 | | -// redirectedFromBank.php |
| 3 | +use Ease\Shared as Shr; |
| 4 | +use Ease\Functions as Fnc; |
4 | 5 |
|
5 | | -// Load Ease Framework |
6 | | -require_once __DIR__ . '/vendor/autoload.php'; |
| 6 | +require_once dirname(__DIR__) . '/vendor/autoload.php'; |
7 | 7 |
|
8 | | -// Initialize Ease Framework and load .env file |
9 | | -\Ease\Shared::init(['.env'], __DIR__); |
| 8 | +Shr::init(['CLIENT_ID', 'CLIENT_SECRET'], dirname(__DIR__) . '/.env'); |
10 | 9 |
|
11 | 10 | // Use environment variables |
12 | | -$clientId = \Ease\Functions::cfg('CLIENT_ID'); |
13 | | -$clientSecret = \Ease\Functions::cfg('API_KEY'); |
14 | | -$redirectUri = 'http://localhost/php-csas-webapi/Examples/redirectedFromBank.php'; |
15 | | -$tokenUrl = 'https://sandbox.csas.cz/sandbox/api/token'; |
| 11 | +$clientId = Shr::cfg('CLIENT_ID'); |
| 12 | +$clientSecret = Shr::cfg('CLIENT_SECRET'); |
| 13 | +$redirectUri = Shr::cfg('REDIRECT_URI'); |
| 14 | + |
| 15 | +$productionSite = 'https://bezpecnost.csas.cz/api/psd2/fl/oidc/v1'; |
| 16 | +$sandboxSite = 'https://webapi.developers.erstegroup.com/api/csas/sandbox/v1/sandbox-idp'; |
| 17 | +$idpLink = (strtolower(Shr::cfg('API_ENVIRONMENT', 'production')) === 'sandbox') ? $sandboxSite : $productionSite; |
| 18 | + |
| 19 | +$tokenUrl = $idpLink . '/token'; |
16 | 20 |
|
17 | 21 | // Start session |
18 | 22 | session_start(); |
19 | 23 |
|
20 | | -// Check if the authorization code is set |
21 | | -if (isset($_GET['code'])) { |
22 | | - $code = $_GET['code']; |
| 24 | +if (PHP_SAPI == 'cli') { |
| 25 | + parse_str($argv[1], $params); |
| 26 | + $code = array_key_exists('code', $params) ? $params['code'] : ''; |
| 27 | +} else { |
| 28 | + $code = array_key_exists('code', $_GET) ? $_GET['code'] : ''; |
| 29 | +} |
23 | 30 |
|
| 31 | +// Check if the authorization code is set |
| 32 | +if ($code) { |
24 | 33 | // Prepare the POST request to exchange the authorization code for an access token |
25 | 34 | $postFields = [ |
26 | 35 | 'grant_type' => 'authorization_code', |
|
35 | 44 | curl_setopt($ch, CURLOPT_POST, true); |
36 | 45 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields)); |
37 | 46 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 47 | + curl_setopt($ch, CURLOPT_VERBOSE, 1); |
38 | 48 |
|
39 | 49 | $response = curl_exec($ch); |
| 50 | + $info = curl_getinfo($ch); |
40 | 51 | curl_close($ch); |
41 | 52 |
|
42 | 53 | $responseData = json_decode($response, true); |
|
47 | 58 | echo 'Access token obtained successfully!'; |
48 | 59 | } else { |
49 | 60 | echo 'Error obtaining access token!'; |
| 61 | + |
| 62 | + var_dump($info); |
50 | 63 | } |
51 | 64 | } else { |
52 | 65 | echo 'Authorization code not found!'; |
|
0 commit comments