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

AuthMiddleware / AccessToken is not a object.  #42

@traedamatic

Description

@traedamatic

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions