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

Example suggests multiple providers based on keycloak with different names, but that doesn't work. #141

Open
MaPePeR opened this issue Nov 16, 2020 · 0 comments

Comments

@MaPePeR
Copy link

MaPePeR commented Nov 16, 2020

Hey!

Issue

The example configuration suggests one could use the name attribute in the provider configuration to configure multiple providers based on keycloak, but that doesn't work, because the name property is ignored.

        // keycloak
        'keycloak' => [
            // 'name' => 'abc', // override for multiple providers based on keycloak
            'baseUrl' => 'https://keycloak_server/auth',
            'realm' => 'your_master',
            'applicationId' => 'your_client',
            'applicationSecret' => 'your_client_uuid4_secret',
            'scope' => [
                'email', 'profile' // openid will be always added
            ],
        ],

My env

PHP: please write it

Library: SocialConnect/Auth

Provider: Keycloak, but mostly a problem of Auth/CollectionFactory

Provider options:

These do not work, because same key cannot appear twice in an array:

return [
    'redirectUri' => 'http://localhost:8000/auth/cb/${provider}/',
    'provider' => [
        //This is ignored, because key is not unique in array:
        'keycloak' => [
            'name' => 'keycloak1', // override for multiple providers based on keycloak
            'baseUrl' => 'https://keycloak_server/auth',
            //[...]
        ],
       'keycloak' => [
           'name' => 'keycloak2', // override for multiple providers based on keycloak
            'baseUrl' => 'https://keycloak_server2/auth',
            //[...]
        ],
    ]
];

That also doesn't work, because then it is not accepted as a keycloak provider:

return [
    'redirectUri' => 'http://localhost:8000/auth/cb/${provider}/',
    'provider' => [
        'keycloak1' => [
            'name' => 'keycloak1', // override for multiple providers based on keycloak
            'baseUrl' => 'https://keycloak_server/auth',
            //[...]
        ],
       'keycloak2' => [
           'name' => 'keycloak2', // override for multiple providers based on keycloak
            'baseUrl' => 'https://keycloak_server2/auth',
            //[...]
        ],
    ]
];

I think what you really want is:

return [
    'redirectUri' => 'http://localhost:8000/auth/cb/${provider}/',
    'provider' => [
        'keycloak1' => [
            'base_provider' => 'keycloak',
            'baseUrl' => 'https://keycloak_server/auth',
            //[...]
        ],
       'keycloak2' => [
           'base_provider' => 'keycloak',
            'baseUrl' => 'https://keycloak_server2/auth',
            //[...]
        ],
    ]
];

and then have something like this in Auth/CollectionFactory::factory (untested):

    /**
     * @param string $id
     * @param array $parameters
     * @param Service $service
     * @return \SocialConnect\Provider\AbstractBaseProvider
     */
    public function factory($id, array $parameters, Service $service)
    {
        $id = strtolower($id);
 //Added code:
        if (isset($parameters['base_provider']) {
            $id = strtolower($parameters['base_provider'])
        }
// End of added code

        if (!isset($this->providers[$id])) {
            throw new LogicException('Provider with $id = ' . $id . ' doest not exist');
        }

        /** @var string $providerClassName */
        $providerClassName = $this->providers[$id];
       // [...]
    }

Thanks 😺

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

1 participant