stevenmaguire / oauth2-microsoft

Microsoft OAuth 2.0 support for the PHP League's OAuth 2.0 Client
MIT License
68 stars 41 forks source link

set the link in the constructor so that the toArray function includes… #3

Closed krasi-georgiev closed 9 years ago

krasi-georgiev commented 9 years ago

… the correct link

stevenmaguire commented 9 years ago

I don't think this proposed solution is appropriate.

  1. The toArray method is intended to provide you with the raw payload of the original response.
  2. The accessor methods are meant to be used to access "opinionated" results of the contents of the raw payload for "commonly" used information.
  3. Your proposed solution directly manipulates the raw payload within the resource owner object, which would cause the getUrls accessor method to return an incorrect result.
krasi-georgiev commented 9 years ago

Is there another way to get this properly coded ?

stevenmaguire commented 9 years ago

You can retrieve the user's information using the opinions in this package by doing the following:

$user = $provider->getResourceOwner($token);

echo $user->getId();
echo $user->getEmail();
echo $user->getFirstname();
echo $user->getLastname();
echo $user->getImageurl();
echo $user->getName();
echo $user->getUrls();

or you can get the raw data that was returned from the API request and process it within your project

$user = $provider->getResourceOwner($token);

print_r($user->toArray());

If you would like to contribute to the resource owner object and improve the accessor methods it provides, that is just fine so long as the accessor methods do not change the underlying array, as you previously requested.