Contains a list of other AuthenticationMethod instances which will be used to verify requests.
This is useful if your API has several acceptable authentication methods
and you want to support them all with a single verify()
call.
This class itself implements the AuthenticationMethod interface, so it can be used in place of single instances everywhere.
Instances can be used for authentication:
the authenticate()
call will always be delegated
to the first instance in the stack.
- Full class name:
mle86\RequestAuthentication\MethodStack
- Class file: src/MethodStack.php
- Inheritance:
- implements AuthenticationMethod
__construct (iterable $methods)
Takes a list of AuthenticationMethod instances or class names. Class names will be instantiated (which requires them to have a public constructor without required arguments).
The list may not be empty.
-
authenticate (RequestInfo $request, string $apiClientId, string $apiClientKey): array
Proxy forAuthenticationMethod::authenticate()
of the first method in the stack. -
verify (RequestInfo $request, KeyRepository $keys): void
CallsAuthenticationMethod::verify()
on all method instances in the stack (in their original order) until one of them verifies the request.
All InvalidAuthenticationExceptions/MissingAuthenticationHeaderExceptions/CryptoErrorExceptions are ignored.
If none of the method instances accept the input, an InvalidAuthenticationException is thrown. -
getClientId (RequestInfo $request): string
CallsAuthenticationMethod::verify()
on all method instances in the stack (in their original order) until one of them returns the client ID.
All InvalidAuthenticationExceptions/MissingAuthenticationHeaderExceptions/CryptoErrorExceptions are ignored.
If none of the method instances accept the input, an InvalidAuthenticationException is thrown.
⚠ NB: It is only safe to call this method ifverify()
has been called before and if the last successfulverify()
call had the same request argument. Otherwise, the wrong method may be chosen which might return an incorrect client id. The RequestVerifier helper class does this correctly.
getMethods (): array
Returns the contained AuthenticationMethod instances in their original order.