public override void WriteToken(XmlWriter writer, SecurityToken token)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (token == null)
{
throw new ArgumentNullException("token");
}
//Contract.EndContractBlock();
var accToken = token as AccessSecurityToken;
if (accToken == null)
{
throw new ArgumentException("token");
}
// create the token payload XML
var xml = new XElement(_ns + AccessSecurityToken.TokenName, new XAttribute("id", accToken.Id),
new XElement(_ns + "resource", accToken.Resource),
new XElement(_ns + "subject", accToken.SubjectName),
new XElement(_ns + "expires", accToken.ValidTo.ToString(DateTimeFormats.Generated, CultureInfo.InvariantCulture)));
// create the digital signature of the token XML and append it to the token
var sig = SignToken(xml, accToken.IssuerCertificate);
xml.Add(sig);
writer.WriteNode(XmlReader.Create(new StringReader(xml.ToString())), false);
}