Skip to content

Commit 909dec0

Browse files
committed
example fix; resource owner fix
1 parent f5b8e91 commit 909dec0

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,22 @@ if (!isset($_GET['code'])) {
4949

5050
// Get resource owner
5151
try {
52-
$resourceOwner = $amazon->getResourceOwner($accessToken);
52+
$resourceOwner = $amazonProvider->getResourceOwner($accessToken);
5353
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
5454
exit($e->getMessage());
5555
}
5656

5757
// Now you can store the results to session etc.
5858
$_SESSION['accessToken'] = $accessToken;
5959
$_SESSION['resourceOwner'] = $resourceOwner;
60+
61+
var_dump(
62+
$resourceOwner->getId(),
63+
$resourceOwner->getName(),
64+
$resourceOwner->getPostalCode(),
65+
$resourceOwner->getEmail(),
66+
$resourceOwner->toArray()
67+
);
6068
}
6169
```
6270

src/Provider/AmazonResourceOwner.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(array $response = array())
3333
*/
3434
public function getId()
3535
{
36-
return $this->getValueByKey($this->response, 'data.0.id');
36+
return $this->getValueByKey($this->response, 'user_id');
3737
}
3838

3939
/**
@@ -43,29 +43,27 @@ public function getId()
4343
*/
4444
public function getName()
4545
{
46-
$firstName = $this->getValueByKey($this->response, 'data.0.firstName') ?: '';
47-
$lastName = $this->getValueByKey($this->response, 'data.0.lastName') ?: '';
48-
return $firstName . ($firstName && $lastName ? ' ' : '') . $lastName;
46+
return $this->getValueByKey($this->response, 'name');
4947
}
5048

5149
/**
52-
* Get resource owner username
50+
* Get resource owner postal code
5351
*
5452
* @return string|null
5553
*/
56-
public function getUsername()
54+
public function getPostalCode()
5755
{
58-
return null;
56+
return $this->getValueByKey($this->response, 'postal_code');
5957
}
6058

6159
/**
62-
* Get resource owner location
60+
* Get resource owner email
6361
*
6462
* @return string|null
6563
*/
66-
public function getLocation()
64+
public function getEmail()
6765
{
68-
return null;
66+
return $this->getValueByKey($this->response, 'email');
6967
}
7068

7169
/**

0 commit comments

Comments
 (0)