Skip to content

Commit

Permalink
Allow createUserCallable to return user entity too
Browse files Browse the repository at this point in the history
  • Loading branch information
ojhaujjwal committed Aug 22, 2014
1 parent eec2781 commit d92d328
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ return [
$userProvider = new \Hrevert\OauthClient\Entity\UserProvider();
$userProvider->setUser($user);

return $userProvider;
return $userProvider;

// or just

$user = ......;

return $user;
}
]
];
Expand Down
12 changes: 11 additions & 1 deletion src/Grant/Oauth2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use League\OAuth2\Client\Exception\IDPException;
use ZfrOAuth2\Server\Grant\AuthorizationServerAwareInterface;
use ZfrOAuth2\Server\Grant\AuthorizationServerAwareTrait;
use Hrevert\OauthClient\Entity\UserProvider;
use Hrevert\OauthClient\Model\UserInterface;

class Oauth2Client extends AbstractGrant implements AuthorizationServerAwareInterface
{
Expand Down Expand Up @@ -124,8 +126,16 @@ public function createTokenResponse(HttpRequest $request, Client $client = null,
// access token is valid but the user does not exists
$createUserCallable = $this->options->getCreateUserCallable();

/** @var \Hrevert\OauthClient\Model\UserProviderInterface */
// by default, we expect the callable to return instance of "Hrevert\OauthClient\Model\UserProviderInterface"
// because the developer may have extended the default implementation
// Alternatively the callable may return user entity directly
$userProvider = $createUserCallable($userDetails);
if ($userProvider instanceof UserInterface) {
$user = $userProvider;
$userProvider = new UserProvider;
$userProvider->setUser($user);
}

$userProvider->setProviderUid($userDetails->uid);
$userProvider->setProvider($provider);
}
Expand Down

0 comments on commit d92d328

Please sign in to comment.