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

How can I use the implementation as a dynamically multi-tenant application? #403

Open
djpysu opened this issue Apr 25, 2023 · 2 comments
Open

Comments

@djpysu
Copy link

djpysu commented Apr 25, 2023

Hello.

I would like to use the oauth2-client-bundle for a multitenant application with multiple Azure apps but, I have two issues:

First of all, How can I get the credentials and options from the database directly in the yaml config file?

knpu_oauth2_client:
    clients:
        azure_1:
            type: azure
            client_id: 'x'
            redirect_route: 'edit_company'
            redirect_params: { id: '1' }
            client_secret: 'x'

And secondly, how can I dynamically add new entries to this container?
For example azure_2.

Is this possible?

@elavrom
Copy link

elavrom commented Jun 9, 2023

Hi there,

I was wondering the same thing because I also wanted to have dynamic providers, so I worked on something and I found a solution (using method I'm pretty sure I shouldn't use, but hey, a workaround is a workaround).

I put all the files needed (+ a fixture for example) in this gist.

In this very simple example, there isn't any security consideration. Of course, client apps credentials should be stored way more securely than in a plain text field in your database.

Hope this helps !

@r4cker
Copy link

r4cker commented Jan 19, 2024

I had the same request and I did like this :

knpu_oauth2_client.yaml

knpu_oauth2_client:
    clients:
        azure_1:
            type: azure
            client_id: 'x'
            redirect_route: 'edit_company'
            redirect_params: { id: '1' }
            client_secret: 'x'
        azure_2:
            type: azure
            client_id: 'x'
            redirect_route: 'edit_company'
            redirect_params: { id: '1' }
            client_secret: 'x'

In your controller

/**
     * Link to this controller to start the "connect" process
     *
     * @Route("/connect/azure", name="connect_azure_start")
     */
    public function connectAction(Request $request,ClientRegistry $clientRegistry)
    {
        $domain = $request->request->get('domain');
      if($domain=='domain1'){
       $type = = "azure_1";
      }else{
       $type = = "azure_2";
      }
        $client = $clientRegistry
            ->getClient($type); 

        return
            $client->redirect([
                'public_profile', 'email' 
            ]);
    }

It s not dynamique tho....

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

3 participants