Closed dreamsbond closed 7 years ago
Not sure if I got your question however you can get current account/user from container with
/** @var AccountManagerInterface $manager */
/** @var PassportAccountInterface $account */
$manager = $container->get(AccountManagerInterface::class);
$account = $manager->getAccount();
passport has some predifined user properties such is identity
howerver it also has all user properties which could be accessed with getProperty()
$firstName = $account->getProperty('first_name');
As for /revoke
endpoint, there is no such 'standard' entry, however you can get TokenRepositoryInterface
from container and disable a token
/** @var TokenRepositoryInterface $repo */
$repo = $container->get(TokenRepositoryInterface::class);
$repo->readByCode('...', 3600);
$repo->readByValue('...', 3600);
$token = $repo->readByRefresh('...', 3600);
$repo->disable($token->getIdentifier());
with createBodyTokenResponse in BasePassportServer, token information returned as { "access_token": "b0e6c4c9933236439101c55e90a52154594a2f0913d5d", "token_type": "bearer", "expires_in": 3600, "refresh_token": "2796b9cace09892ee2ec56ac9dc8781e594a2f0913d98", "scope": "manage_users" }
i am thinking if it could return corresponding user identity information like: { "id_user": "1", "access_token": "b0e6c4c9933236439101c55e90a52154594a2f0913d5d", "token_type": "bearer", "expires_in": 3600, "refresh_token": "2796b9cace09892ee2ec56ac9dc8781e594a2f0913d98", "scope": "manage_users" }
for /revoke, do you mean i could create an endpoint to do so manually?
Added feature https://github.com/limoncello-php/framework/issues/52
It needs some extra functionality in Passport
module. I've added preliminary implementation which I'm planning to finalize later today.
While testing the code I've found a way to improve the code so finalizing takes a bit more.
Passport
settings could have a methods for adding extra properties
/**
* @inheritdoc
*/
protected function getTokenCustomPropertiesProvider()
{
return [self::class, 'tokenCustomPropertiesProvider'];
}
public static function tokenCustomPropertiesProvider(ContainerInterface $container, TokenInterface $token): array
{
return [
'user_id' => $token->getUserIdentifier(),
];
}
added to 0.6.17 I'm closing the question. Feel free to contact if you have any further questions.
noted ^^
tried and tested:
assert($customPropsProvider === null || $this->checkPublicStaticCallable(
$customPropsProvider,
[ContainerInterface::class, TokenInterface::class],
'array'
));
failed at the point of $customPropsProvider === null and checkPublicStaticCallable
@dreamsbond check the method signature. This line ensures the method must have 2 typed parameters and typed return type as array
.
@neomerx yes, having the method typed return as array resolved the issue. but asserting $customPropsProvider === null failed
@neomerx keep telling ErrorException: assert(): assert($customPropsProvider === null) failed
@dreamsbond it does not have a check for signature AND null
. It checks either for null
OR for a method with the proper signature.
it is quite rare to me..... after i tried composer dump-autoload
the issue gone..........
other than standard attribute from oauth2 is it capable to return user identity information via the /token authentication endpoint
beside, is a /revoke endpoint available?