Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/Token/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
*
* @link http://tools.ietf.org/html/rfc6749#section-1.4 Access Token (RFC 6749, §1.4)
*/
class AccessToken implements AccessTokenInterface, ResourceOwnerAccessTokenInterface, SettableRefreshTokenInterface
class AccessToken implements
AccessTokenInterface,
ArrayableAccessTokenInterface,
ResourceOwnerAccessTokenInterface,
SettableRefreshTokenInterface
{
/**
* @var string
Expand Down Expand Up @@ -222,11 +226,11 @@ public function __toString()
{
return (string) $this->getToken();
}

/**
* @inheritdoc
*/
public function jsonSerialize()
public function toArray()
{
$parameters = $this->values;

Expand All @@ -248,4 +252,12 @@ public function jsonSerialize()

return $parameters;
}

/**
* @inheritdoc
*/
public function jsonSerialize()
{
return $this->toArray();
}
}
16 changes: 16 additions & 0 deletions src/Token/ArrayableAccessTokenInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace League\OAuth2\Client\Token;

use ReturnTypeWillChange;

interface ArrayableAccessTokenInterface
{
/**
* Returns an array of parameters provided to the access token
*
* @return array
*/
#[ReturnTypeWillChange]
public function toArray();
}
17 changes: 17 additions & 0 deletions test/src/Token/AccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,21 @@ public function testValues()

self::tearDownForBackwardsCompatibility();
}

public function testToArray()
{
$options = [
'access_token' => '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();
}
}
Loading