Napojení na ErsteGroup API

jAkErCZ
Člen | 321
+
-5
-

Zdravím,
takže aktuálně jsem došel do fáze kdy žádám o generování access_tokenu Žádost o token

Po potvrzení mě to vrátí na stránku kde jsem o token žádal a získám Přístup

Teď otázka proč mi ten sandbox nevrátil i refresh token? Je to tím že to je testovací verze banky a až na produkční verzi tohle je?

Další věc po vrácení na stránku mi tam háže nějakou informaci

status => 404
	errors =>
		0 =>
		error => "endpoint not found" (18)

Zkoušel sem najít tento problém ale nic sem o tom nenašel logicky mě napadá že chybí nějaký výstup ale jak jej docílit?

A další věc pokouším se získat historii z přiložených testujících účtů ale top se mi také nevede.

vycházím z kódu který byl OAuth 2.0 Client

  /**
     * @throws \Nette\Application\AbortException
     */
    public function ActionBank(){
        // Note: the GenericProvider requires the `urlAuthorize` option, even though
        // it's not used in the OAuth 2.0 client credentials grant type.
        $provider = new \League\OAuth2\Client\Provider\GenericProvider([
            'clientId'                => 'CLIENT_ID',    // The client ID assigned to you by the provider
            'clientSecret'            => 'SECRET_ID',    // The client password assigned to you by the provider
            'redirectUri'             => 'http://localhost/Intranet/homepage/bank',
            'urlAuthorize'            => 'https://webapi.developers.erstegroup.com/api/csas/sandbox/v1/sandbox-idp/auth',
            'urlAccessToken'          => 'https://webapi.developers.erstegroup.com/api/csas/sandbox/v1/sandbox-idp/token',
            'urlResourceOwnerDetails' => 'https://webapi.developers.erstegroup.com/api/csas/public/sandbox/v1/accounts'
        ]);

// If we don't have an authorization code then get one
        if (!isset($_GET['code'])) {

            // Fetch the authorization URL from the provider; this returns the
            // urlAuthorize option and generates and applies any necessary parameters
            // (e.g. state).
            $authorizationUrl = $provider->getAuthorizationUrl();

            // Get the state generated for you and store it to the session.
            $_SESSION['oauth2state'] = $provider->getState();

            // Redirect the user to the authorization URL.
            header('Location: ' . $authorizationUrl);
            exit;

// Check given state against previously stored one to mitigate CSRF attack
        } elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) {

            if (isset($_SESSION['oauth2state'])) {
                unset($_SESSION['oauth2state']);
            }

            exit('Invalid state');

        } else {

            try {
                // Try to get an access token using the authorization code grant.
                $accessToken = $provider->getAccessToken('authorization_code', [
                    'code' => $_GET['code']
                ]);

                // We have an access token, which we may use in authenticated
                // requests against the service provider's API.
                echo 'Access Token: ' . $accessToken->getToken() . "<br>";
                echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "<br>";
                echo 'Expired in: ' . $accessToken->getExpires() . "<br>";
                echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "<br>";

                // Using the access token, we may look up details about the
                // resource owner.
                $resourceOwner = $provider->getResourceOwner($accessToken);
                bdump($accessToken);
                bdump($resourceOwner->toArray());

                // The provider provides a way to get an authenticated API request for
                // the service, using the access token; it returns an object conforming
                // to Psr\Http\Message\RequestInterface.
                $request = $provider->getAuthenticatedRequest(
                    'GET',
                    'https://webapi.developers.erstegroup.com/api/csas/public/sandbox/v1/accounts',
                    $accessToken
                );

            bdump($request->getBody());


                if ($accessToken->hasExpired()) {
                    $newAccessToken = $provider->getAccessToken('refresh_token', [
                        'refresh_token' => $accessToken->getRefreshToken()
                    ]);


                    bdump($newAccessToken);
                    // Purge old access token and store new access token to your data store.
                }

            } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {

                // Failed to get the access token or user details.
                echo $e->getMessage();

            }

        }
        $this->terminate();
    }

Takže bych byl rád kdyby mi někdo zkusil nasměrovat k úspěšnému závěru.

Díky všem za pomoc :)

Editoval jAkErCZ (24. 6. 2019 11:58)