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

Create ResourceOwnerEmailInterface #958

Open
eerison opened this issue Jul 3, 2022 · 7 comments
Open

Create ResourceOwnerEmailInterface #958

eerison opened this issue Jul 3, 2022 · 7 comments

Comments

@eerison
Copy link

eerison commented Jul 3, 2022

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
Copy link
Contributor

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
Copy link
Author

eerison commented Aug 17, 2022

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
Copy link
Contributor

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
Copy link
Author

eerison commented Aug 18, 2022

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

@Austomos
Copy link
Contributor

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
Copy link
Author

eerison commented Sep 2, 2022

any feedback here? 👀

@eerison
Copy link
Author

eerison commented Sep 2, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants