Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Getter Methods For Retrieving User Information #710

Closed
wants to merge 3 commits into from
Closed
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
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
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