artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
684 stars 217 forks source link

Manually setting access token #111

Closed simplenotezy closed 8 years ago

simplenotezy commented 9 years ago

How can I manually set the access token? I.e.:

$fb = OAuth::consumer( 'Facebook' );
$fb->setAccessToken('some_long_access_token');
$fb->request('/me');
simplenotezy commented 9 years ago

I created a method, that enable the user to assign the access_token manually. Any chance you could pull this one in?

/**
 * set access token
 */
public function setAccessToken($token) {
    /**
     * Data
     */

        $data = array(
                'access_token' => $token
            );

    /**
     * Prepare token
     */

        $token = new StdOAuth2Token();
        $token->setAccessToken($data['access_token']);

    /**
     * Params
     */

        $token->setExtraParams($data);

    /**
     * Set code
     */

        $this->storage->storeAccessToken($this->service(), $token);
}
mohamedfasil commented 9 years ago

You dont need any additional function to set the access token, the correct way to do this is,

use OAuth\OAuth2\Token\StdOAuth2Token;
$token_interface = new StdOAuth2Token($token);
$fb = OAuth::consumer( 'Facebook' );
$token = $fb->getStorage()->storeAccessToken('Facebook', $token_interface);
akaramires commented 9 years ago

@mohamedfasil thank you for answer!