Skip to content

Commit

Permalink
Develop (#10)
Browse files Browse the repository at this point in the history
* Enhancement #9

* CS.
  • Loading branch information
overtrue committed Apr 29, 2016
1 parent 4aeba2e commit c9b6455
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ The `$user->getOriginal()` method will return an array of the API raw response.
You can get the access token instance of current session by call `$user->getToken()` or `$user->getAccessToken()` or `$user['token']` .


### Get user with access token

```php
$accessToken = new AccessToken(['access_token' => $accessToken]);
$user = $socialite->user($accessToken);
```


### Custom Session or Request instance.

You can set the request with your custom `Request` instance which instanceof `Symfony\Component\HttpFoundation\Request`.
Expand Down Expand Up @@ -228,4 +236,4 @@ Enjoy it! :heart:

# License

MIT
MIT
1 change: 1 addition & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace Overtrue\Socialite;

use ArrayAccess;
use InvalidArgumentException;

/**
* Class Config.
Expand Down
4 changes: 3 additions & 1 deletion src/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public function redirect();
/**
* Get the User instance for the authenticated user.
*
* @param \Overtrue\Socialite\AccessTokenInterface $token
*
* @return \Overtrue\Socialite\User
*/
public function user();
public function user(AccessTokenInterface $token = null);
}
10 changes: 5 additions & 5 deletions src/Providers/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ protected function formatScopes(array $scopes, $scopeSeparator)
/**
* {@inheritdoc}
*/
public function user()
public function user(AccessTokenInterface $token = null)
{
if ($this->hasInvalidState()) {
if (is_null($token) && $this->hasInvalidState()) {
throw new InvalidStateException();
}

$user = $this->getUserByToken(
$token = $this->getAccessToken($this->getCode())
);
$token = $token ?: $this->getAccessToken($this->getCode());

$user = $this->getUserByToken($token);

$user = $this->mapUserToObject($user)->merge(['original' => $user]);

Expand Down

0 comments on commit c9b6455

Please sign in to comment.