public function buildAuthnRequest()
    {
        $authnRequest = (new AuthnRequest())
            ->setAssertionConsumerServiceURL($this->getMetadata()->getFirstAcs()->getLocation())
            ->setProtocolBinding($this->getMetadata()->getFirstAcs()->getBinding())
            ->setID(Helper::generateID())
            ->setIssueInstant(new \DateTime())
            ->setDestination($this->getMetadata()->getFirstSso()->getLocation())
            ->setIssuer(new Issuer($this->getMetadata()->getServiceProvider()->getEntityID()))
            ->setRelayState(Helper::generateID());

        if ($this->getMetadata()->getFirstIdpSsoDescriptor()->getWantAuthnRequestsSigned()) {
            $authnRequest->setSignature(
                new SignatureWriter(
                    $this->getMetadata()
                        ->getFirstSpSsoDescriptor()
                        ->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
                        ->getCertificate(),
                    KeyHelper::createPrivateKey($this->getPrivateKey(), '')
                )
            );
        }

        return $authnRequest;
    }