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

Multiple authentication adapters per API #16

Open
weierophinney opened this issue Dec 31, 2019 · 6 comments
Open

Multiple authentication adapters per API #16

weierophinney opened this issue Dec 31, 2019 · 6 comments

Comments

@weierophinney
Copy link
Contributor

It could be great to add support for multiple authentication adapter per API at it is possible in Github API.

See https://developer.github.com/v3/auth/


Originally posted by @nuxwin at zfcampus/zf-mvc-auth#93

@weierophinney
Copy link
Contributor Author

https://github.com/zfcampus/zf-mvc-auth#sub-key-adapters

This part of the README.md for this module shows HTTP and OAuth2.


Originally posted by @TomHAnderson at zfcampus/zf-mvc-auth#93 (comment)

@weierophinney
Copy link
Contributor Author

@TomHAnderson

Yes, but

...
The name provided will be used as the authentication type for purposes of mapping APIs to an authentication adapter.
...

For but, this look like we can map only one named adapter to one API at time.


Originally posted by @nuxwin at zfcampus/zf-mvc-auth#93 (comment)

@weierophinney
Copy link
Contributor Author

My understanding is the map can map to an array of adapters. Consider this hear-say but I suggest you try it.

    'zf-mvc-auth' => array(
        'authentication' => array(
            'map' => array(
                'Api\\V1' => ['pdo', 'oauth2_doctrine'],
            ),
        ),
    ),

Originally posted by @TomHAnderson at zfcampus/zf-mvc-auth#93 (comment)

@weierophinney
Copy link
Contributor Author

@TomHAnderson

Same idea here. I'm not sure about the list possibility ;) At least, in apigility UI we cannot map multiple adapters atm. The only way is to use the fallback feature with andy adapters. Eg; When no adapter is specified for a given API, attempt is made by the DefaultAuthenticationListener event listener to retrieve the adapter type to use from the request and thus, the first andy adapter which match this type is used (at least, this is what I understand from the code).

My personal through was something like

The adapter type should be first retrieved from the request in any case, and once done checked against the map (API modules to allowed authentication adapters.).

In such case, we should be allowed to do something like

    'zf-mvc-auth' => array(
        'authentication' => array(
            'map' => array(
                'Status\\V1' => array(
                    'named_adapter_1',
                    'named_adapter_2',
                )
            ),
        ),
    ),

as you said ;)


Originally posted by @nuxwin at zfcampus/zf-mvc-auth#93 (comment)

@weierophinney
Copy link
Contributor Author

@TomHAnderson

For me it look like we cannot specify list of adapters in the map currently.

...
    /**
     * Match the controller to an authentication type, based on the API to
     * which the controller belongs.
     *
     * @param null|RouteMatch $routeMatch
     * @return string|false
     */
    private function getTypeFromMap(RouteMatch $routeMatch = null)
    {
        if (! $routeMatch) {
            return false;
        }

        $controller = $routeMatch->getParam('controller', false);

        if (false === $controller) {
            return false;
        }

        foreach ($this->authMap as $api => $type) {
            $api = rtrim($api, '\\') . '\\';
            if (strlen($api) > strlen($controller)) {
                continue;
            }

            if (0 === strpos($controller, $api)) {
                return $type;
            }
        }

        return false;
    }
...

See https://github.com/zfcampus/zf-mvc-auth/blob/master/src/Authentication/DefaultAuthenticationListener.php#L209


Originally posted by @nuxwin at zfcampus/zf-mvc-auth#93 (comment)

@weierophinney
Copy link
Contributor Author

Hi,

Because we needed this feature for our project, we implemented it (see qapa/zf-mvc-auth@b30d83e)

Basically, if an array of types is defined for an API, we try to find the type extracted from request in this array.


Originally posted by @ronan-gloo at zfcampus/zf-mvc-auth#93 (comment)

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