nextHandler = $nextHandler; $this->authResolver = $authResolver; $this->api = $api; } /** * @param CommandInterface $command * * @return Promise */ public function __invoke(CommandInterface $command) { $nextHandler = $this->nextHandler; $serviceAuth = $this->api->getMetadata('auth') ?: []; $operation = $this->api->getOperation($command->getName()); $operationAuth = $operation['auth'] ?? []; $unsignedPayload = $operation['unsignedpayload'] ?? false; $resolvableAuth = $operationAuth ?: $serviceAuth; if (!empty($resolvableAuth)) { if (isset($command['@context']['auth_scheme_resolver']) && $command['@context']['auth_scheme_resolver'] instanceof AuthSchemeResolverInterface ){ $resolver = $command['@context']['auth_scheme_resolver']; } else { $resolver = $this->authResolver; } $selectedAuthScheme = $resolver->selectAuthScheme( $resolvableAuth, ['unsigned_payload' => $unsignedPayload] ); if (!empty($selectedAuthScheme)) { $command['@context']['signature_version'] = $selectedAuthScheme; } } return $nextHandler($command); } }