public function attach()
    {
        return function (callable $handler) {

            return function (RequestInterface $request, array $options) use ($handler) {

                $createdAt = $this->getCreatedAt()->format('c');
                $nonce = $this->generateNonce();
                $digest = $this->generateDigest($nonce, $createdAt, $this->password);

                $xwsse = array(
                    sprintf('Username="%s"', $this->username),
                    sprintf('PasswordDigest="%s"', $digest),
                    sprintf('Nonce="%s"', $nonce),
                    sprintf('Created="%s"', $createdAt)
                );

                $request = $request->withHeader('Authorization', 'WSSE profile="UsernameToken"');
                $request = $request->withHeader('X-WSSE', sprintf('UsernameToken %s', implode(', ', $xwsse)));

                return $handler($request, $options);
            };
        };
    }