thephpleague / oauth2-client

Easy integration with OAuth 2.0 service providers.
http://oauth2-client.thephpleague.com
MIT License
3.64k stars 751 forks source link

Create ResourceOwnerEmailInterface #958

Open eerison opened 2 years ago

eerison commented 2 years ago

Hi I was trying to get the identify of third party, but I can see the most of the others dependencies like oauth2-client, linkedin and so on, use the getId() with the id provider by the api, it's kind make sense :), But I would like to getEmail too

then my suggestion is create a new Interface like

interface ResourceOwnerEmailInterface extends ResourceOwnerInterface 
{
    public function getEmail(): string;
}

and for the api that has email implements email, uses ResourceOwnerEmailInterface instead of ResourceOwnerInterface

the second option is

interface ResourceOwnerEmailInterface
{
    public function getEmail(): string;
}

and the Owner class implements both interface ResourceOwnerEmailInterface and ResourceOwnerInterface, But I'm not sure about this, it can be useful or not! but the positive thing about this is, we can create others interface like

Email, firstName, Lastname and image, the for the api that has those information just need to add those interfaces.

it will be like this

class ApiBlaBlaOwner implements ResourceOwnerEmailInterface, ResourceOwnerNameInterface, ResourceOwnerImageInterface, ResourceOwnerInterface

Because those fields are quite useful for most of applications

Austomos commented 2 years ago

I'm curious. A third party client can extend by itself with any interfaces the ResourceOwnerInterface. Why would you wish to add it to the base?

eerison commented 2 years ago

For now the main reason is: I'm creating a lib to make this oauth2-client works easily for symfony!

then I wan't to add the option to create a user when it doesn't exist, But for this I need to get the return with a object with

identifier (email? maybe), First name, last name, and in case there is image add too!

But the providers need to return this common interface.

Austomos commented 2 years ago

To be honest, I don't know Symfony. Maybe I missed something. But from what I understand about your needs, you can extend AbstractProvider in your library to make your provider. Then, you can create the owner object as you want and you just need to provide it in return of abstract protected function createResourceOwner(array $response, AccessToken $token); (createResourceOwner body is defined in your provider).

Your RessourceOwner can implement the ResourceOwnerInterface and/or any other interface without problem, because this part isn't handle directly by the oauth2-client.

Also, the public function getId(); returns a mixed value, it can be whatever you want (string, array, object, ...).

For example, it's what I done in my third party lib for an REST API. Provider: https://github.com/Austomos/oauth2-chaster-app/blob/8d6d1374098961d70e8a9e4fd211843cfde65e72/src/Provider/ChasterApp.php#L92 RessourceOwner: https://github.com/Austomos/oauth2-chaster-app/blob/8d6d1374098961d70e8a9e4fd211843cfde65e72/src/Provider/ChasterAppResourceOwner.php

eerison commented 2 years ago

Ok, But you are thinking as I'm going to create a new provider, But not it'll be an abstraction of this library,But I can pass many providers, for example:

Austomos commented 2 years ago

I completely understand that you wish keep an abstracted provider and provide more owner ressource interfaces, but you can still do it by extending the AbstractProvider of oauth2-client by your own AbstractProvider and adding more interfaces fir owner ressource. Anyway, I'm not a maintainer, you can still make a PR. I just think you could do your lib without waiting new release of oauth2-client. ;-)

eerison commented 2 years ago

any feedback here? 👀

eerison commented 2 years ago

well I can provide a PR for this, I just want to be sure, that it's agreed!