From c28e518eaa539c7db1a90d2b0845c2061dfbf306 Mon Sep 17 00:00:00 2001 From: Adam Rodriguez Date: Tue, 7 Dec 2021 11:28:54 -0700 Subject: [PATCH] add toArray api to access token --- src/Token/AccessToken.php | 14 +++++++++++--- src/Token/ArrayableAccessTokenInterface.php | 16 ++++++++++++++++ test/src/Token/AccessTokenTest.php | 17 +++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/Token/ArrayableAccessTokenInterface.php diff --git a/src/Token/AccessToken.php b/src/Token/AccessToken.php index 81533c30..08e65666 100644 --- a/src/Token/AccessToken.php +++ b/src/Token/AccessToken.php @@ -22,7 +22,7 @@ * * @link http://tools.ietf.org/html/rfc6749#section-1.4 Access Token (RFC 6749, ยง1.4) */ -class AccessToken implements AccessTokenInterface, ResourceOwnerAccessTokenInterface +class AccessToken implements AccessTokenInterface, ResourceOwnerAccessTokenInterface, ArrayableAccessTokenInterface { /** * @var string @@ -214,11 +214,11 @@ public function __toString() { return (string) $this->getToken(); } - + /** * @inheritdoc */ - public function jsonSerialize() + public function toArray() { $parameters = $this->values; @@ -240,4 +240,12 @@ public function jsonSerialize() return $parameters; } + + /** + * @inheritdoc + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/src/Token/ArrayableAccessTokenInterface.php b/src/Token/ArrayableAccessTokenInterface.php new file mode 100644 index 00000000..a5f87511 --- /dev/null +++ b/src/Token/ArrayableAccessTokenInterface.php @@ -0,0 +1,16 @@ + 'mock_access_token', + 'refresh_token' => 'mock_refresh_token', + 'expires' => time(), + 'resource_owner_id' => 'mock_resource_owner_id', + 'custom_thing' => 'i am a test!', + ]; + + $token = $this->getAccessToken($options); + + $this->assertSame($token->toArray(), $token->jsonSerialize()); + + self::tearDownForBackwardsCompatibility(); + } }