oauth2-client icon indicating copy to clipboard operation
oauth2-client copied to clipboard

Create ResourceOwnerEmailInterface

Open eerison opened this issue 2 years ago • 7 comments

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

eerison avatar Jul 03 '22 11:07 eerison

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?

Austomos avatar Aug 17 '22 11:08 Austomos

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.

eerison avatar Aug 17 '22 11:08 eerison

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

Austomos avatar Aug 17 '22 16:08 Austomos

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:

  • let's say that I'll implement: Create user a user in case it doesn't exist!

    • then you going to authenticate with : google, linkedin, facebook and so on
    • and the createResourceOwner method need to return a common interface between them for I make sure that the response will return the basic data to create an account like : email, first name, last name, and image (it can be optional).

    then my idea for this process works is add the interfaces here and the providers can add in their code, this way I'll have a common interface(s) between all providers that I use (of course In case they implement the interface)

    Note 1: In my case I'm doing an abstraction for symfony, but Other guy can do the samething for other framework like laravel Note 2: my goal in the end is pass the provides into the configuration and it works for all providers passed like

    //some_config_file.yaml
    config_lib_auth:
        providers
            - Provider1
            - Provider2
            - Provider3
            - .......
    

eerison avatar Aug 18 '22 05:08 eerison

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. ;-)

Austomos avatar Aug 18 '22 08:08 Austomos

any feedback here? 👀

eerison avatar Sep 02 '22 09:09 eerison

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

eerison avatar Sep 02 '22 10:09 eerison