Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

AuthMiddleware / AccessToken is not a object. #42

Open
traedamatic opened this issue Jul 28, 2016 · 0 comments
Open

AuthMiddleware / AccessToken is not a object. #42

traedamatic opened this issue Jul 28, 2016 · 0 comments

Comments

@traedamatic
Copy link

Hello,
i run into a strange behavior. First I will explain the scenario. I use the Laravel framework and created a login route for Instagram (as mentioned in the docs). That works fine: The server redirects to Instagram and Instagram does redirect back to correct redirect_url, i entered.

Now I call the setAccessToken with the code returned from Instagram. Note: The variable $instagramManager is a proxy/facade to a Instagram Client instance. (I use this package for that https://github.com/vinkla/laravel-instagram)

$code = $request->query('code', false);

if ($code === false) {
      return response()->redirectTo($instagramManager->getLoginUrl());
}

 $token = $instagramManager->getAccessToken($code);

Everything works fine. I can see the token stored in the variable $token.
Now I am trying to get the users information:

$instagramManager->users()->get()

And the following error appears:

Call to a member function getToken() on string in /var/www/html/vendor/larabros/elogram/src/Http/Middleware/AuthMiddleware.php on line 36

Strange. Some further inspection:

In the Client.php I see from line 240 following code:

 public function setAccessToken(AccessToken $token)
    {
        $this->container->get('config')
            ->set('access_token', json_encode($token->jsonSerialize()));
    }

So the access-token will be saved into the config under the key access_token and very important as json encoded string.

In the AuthMiddleware.php on line 33 I see following code:

$uri = Uri::withQueryValue(
            $request->getUri(),
            'access_token',
            $this->config->get('access_token')->getToken()
        );

What this does is getting the access-token from the configuration and trying to call directly the getToken method on the returned access-token. As we save before the the access_token is a json_encoded string. Therefore it is not possible to call the method getToken.

Do i miss here anything or is this a bug?

traedamatic pushed a commit to traedamatic/elogram that referenced this issue Aug 1, 2016
…etimes a AccessToken class instance is returned from the config and sometimes only a encoded json string. The bug is reported in the main project larabros#42

Adds the .idea  (PHPStorm settings)  folder to the gitignore
Kit-kat1 pushed a commit to Kit-kat1/elogram that referenced this issue Sep 7, 2016
…etimes a AccessToken class instance is returned from the config and sometimes only a encoded json string. The bug is reported in the main project larabros#42

Adds the .idea  (PHPStorm settings)  folder to the gitignore
hassankhan added a commit that referenced this issue Sep 20, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant