From 74e7c6e03cf7ee23443ed130524f9f8eabef00b0 Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 31 May 2019 08:58:21 +0200 Subject: [PATCH 1/2] Use ArrayAccessor in GenericResourceOwner Allow the `resourceOwnerId` to be specified in more formats, like `user.id` --- src/Provider/GenericResourceOwner.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Provider/GenericResourceOwner.php b/src/Provider/GenericResourceOwner.php index f8766148..602a7d60 100644 --- a/src/Provider/GenericResourceOwner.php +++ b/src/Provider/GenericResourceOwner.php @@ -14,11 +14,15 @@ namespace League\OAuth2\Client\Provider; +use League\OAuth2\Client\Tool\ArrayAccessorTrait; + /** * Represents a generic resource owner for use with the GenericProvider. */ class GenericResourceOwner implements ResourceOwnerInterface { + use ArrayAccessorTrait; + /** * @var array */ @@ -46,7 +50,7 @@ public function __construct(array $response, $resourceOwnerId) */ public function getId() { - return $this->response[$this->resourceOwnerId]; + return $this->getValueByKey($this->response, $this->resourceOwnerId); } /** From 1d8b039cd86ac1ccb1cbbdeb54e2e04afa5b0a16 Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 31 May 2019 13:05:14 +0200 Subject: [PATCH 2/2] Get any attribute from GenericResourceOwner --- src/Provider/GenericResourceOwner.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Provider/GenericResourceOwner.php b/src/Provider/GenericResourceOwner.php index 602a7d60..3d44797d 100644 --- a/src/Provider/GenericResourceOwner.php +++ b/src/Provider/GenericResourceOwner.php @@ -53,6 +53,16 @@ public function getId() return $this->getValueByKey($this->response, $this->resourceOwnerId); } + /** + * Gets resource owner attribute by key. The key supports dot notation. + * + * @return mixed + */ + public function getAttribute($key) + { + return $this->getValueByKey($this->response, (string) $key); + } + /** * Returns the raw resource owner response. *