Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access to undefined property aud #39

Open
matt-gnu opened this issue Dec 30, 2016 · 0 comments
Open

access to undefined property aud #39

matt-gnu opened this issue Dec 30, 2016 · 0 comments

Comments

@matt-gnu
Copy link

matt-gnu commented Dec 30, 2016

In current version 2.1.0 we do get (on requests with old/invalid tokens):

PHP Notice:  Undefined property: stdClass::$aud in [...]/vendor/amzn/login-and-pay-with-amazon-sdk-php/PayWithAmazon/Client.php on line 306
PHP Stack trace:
...
PHP  11. PayWithAmazon\Client->getUserInfo() [...]/AmazonGateway.php:153

this is caused by Client.php not checking for errors and unconditionally accessing $data->aud:

public function getUserInfo($accessToken)
    ...
    $response = $httpCurlRequest->httpGet($url);
    $data       = json_decode($response);
    
    if ($data->aud != $this->config['client_id']) {
        // The access token does not belong to us
        throw new \Exception('The Access token entered is incorrect');
    }

You should also catch something like this:

    if (isset($data->error) && $data->error === 'invalid_token') {
        throw new \Exception('The Access token entered is incorrect');
    }

because in that case, $data->aud will not exist. And maybe also throw an exception if $data is empty because of json parsing errors ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant