Skip to content

Commit

Permalink
Merge pull request #1 from jeramyhing/additional-getter-methods
Browse files Browse the repository at this point in the history
Additional Getter Methods For Retrieving User Information
  • Loading branch information
jeramyhing authored Jul 5, 2024
2 parents 7c6f34f + b522375 commit c6924c2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/AbstractUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ public function setRaw(array $user)
return $this;
}

/**
* Get the user's attributes.
*
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}

/**
* Map the given array onto the user's properties.
*
Expand Down
14 changes: 14 additions & 0 deletions src/Contracts/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ public function getEmail();
* @return string|null
*/
public function getAvatar();

/**
* Get the raw user array.
*
* @return array
*/
public function getRaw();

/**
* Get the user's attributes.
*
* @return array
*/
public function getAttributes();
}
40 changes: 40 additions & 0 deletions src/Two/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ class User extends AbstractUser
*/
public $approvedScopes;

/**
* Get the access token for the user.
*
* @return string
*/
public function getToken()
{
return $this->token;
}

/**
* Set the token on the user.
*
Expand All @@ -47,6 +57,16 @@ public function setToken($token)
return $this;
}

/**
* Get the refresh token for the user.
*
* @return string
*/
public function getRefreshToken()
{
return $this->refreshToken;
}

/**
* Set the refresh token required to obtain a new access token.
*
Expand All @@ -60,6 +80,16 @@ public function setRefreshToken($refreshToken)
return $this;
}

/**
* Get the number of seconds the access token is valid for.
*
* @return int
*/
public function getExpiresIn()
{
return $this->expiresIn;
}

/**
* Set the number of seconds the access token is valid for.
*
Expand All @@ -73,6 +103,16 @@ public function setExpiresIn($expiresIn)
return $this;
}

/**
* Get the scopes that were approved by the user during authentication.
*
* @return array
*/
public function getApprovedScopes()
{
return $this->approvedScopes;
}

/**
* Set the scopes that were approved by the user during authentication.
*
Expand Down
1 change: 1 addition & 0 deletions tests/OAuthOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
$this->assertSame('uid', $user->id);
$this->assertSame('foo@bar.com', $user->email);
$this->assertSame(['extra' => 'extra'], $user->user);
$this->assertSame($user->getAttributes(), $user->attributes);
}

public function testExceptionIsThrownWhenVerifierIsMissing()
Expand Down
12 changes: 12 additions & 0 deletions tests/OAuthTwoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public function testTokenRequestIncludesPKCECodeVerifier()
$this->assertSame('refresh_token', $user->refreshToken);
$this->assertSame(3600, $user->expiresIn);
$this->assertSame($user->id, $provider->user()->id);
$this->assertSame($user->getAttributes(), $user->attributes);
$this->assertSame($user->getToken(), $user->token);
$this->assertSame($user->getRefreshToken(), $user->refreshToken);
$this->assertSame($user->getExpiresIn(), $user->expiresIn);
}

public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
Expand All @@ -135,6 +139,10 @@ public function testUserReturnsAUserInstanceForTheAuthenticatedRequest()
$this->assertSame('refresh_token', $user->refreshToken);
$this->assertSame(3600, $user->expiresIn);
$this->assertSame($user->id, $provider->user()->id);
$this->assertSame($user->getAttributes(), $user->attributes);
$this->assertSame($user->getToken(), $user->token);
$this->assertSame($user->getRefreshToken(), $user->refreshToken);
$this->assertSame($user->getExpiresIn(), $user->expiresIn);
}

public function testUserReturnsAUserInstanceForTheAuthenticatedFacebookRequest()
Expand All @@ -156,6 +164,10 @@ public function testUserReturnsAUserInstanceForTheAuthenticatedFacebookRequest()
$this->assertNull($user->refreshToken);
$this->assertSame(5183085, $user->expiresIn);
$this->assertSame($user->id, $provider->user()->id);
$this->assertSame($user->getAttributes(), $user->attributes);
$this->assertSame($user->getToken(), $user->token);
$this->assertSame($user->getRefreshToken(), $user->refreshToken);
$this->assertSame($user->getExpiresIn(), $user->expiresIn);
}

public function testExceptionIsThrownIfStateIsInvalid()
Expand Down

0 comments on commit c6924c2

Please sign in to comment.