2017-04-19 10 views
3

Ich brauche eine Möglichkeit, eine <samlp:response> Nachricht an eine bestimmte URL, seine ziemlich einfach und .NET hilft mir mit Saml2Assertion Klasse, aber ich kann nicht scheinen, einen Weg zu finden diese Behauptung in eine Antwort wickeln und sie serialisieren lassen (oder sogar ohne manuelle Post senden)?Erstellen SAML-Antwort von Assertion in C# 4.5 (WIF)

Saml2Assertion assert = new Saml2Assertion(new Saml2NameIdentifier("SAMLIssuer")); 
assert.Subject = new Saml2Subject(new Saml2NameIdentifier("10001", new Uri("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"))); 
Saml2AuthenticationContext context = new Saml2AuthenticationContext(new Uri("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport")); 
assert.Statements.Add(new Saml2AuthenticationStatement(context, DateTime.Now)); 

string assertion; 
using (var sw = new StringWriter()) 
{ 
    var xws = new XmlWriterSettings(); 
    using (var xw = XmlWriter.Create(sw, xws)) 
    { 
     var handler = new Saml2SecurityTokenHandler(); 
     handler.WriteToken(xw, new Saml2SecurityToken(assert)); 
    } 
    assertion = sw.ToString(); 
} 

Und die XML ich für assert bekommen scheint in Ordnung:

<?xml version="1.0" encoding="utf-16"?> 
<Assertion ID="_fc348927-c0bf-4955-b98f-483043d8dedd" IssueInstant="2017-04-19T11:29:38.464Z" Version="2.0" xmlns="urn:oasis:names:tc:SAML:2.0:assertion"> 
    <Issuer>SAMLIssuer</Issuer> 
    <Subject> 
     <NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">10001</NameID> 
    </Subject> 
    <AuthnStatement AuthnInstant="2017-04-19T11:29:39.040Z"> 
     <AuthnContext> 
      <AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</AuthnContextClassRef> 
     </AuthnContext> 
    </AuthnStatement> 
</Assertion> 

Also, was jetzt? Wie bekomme ich von meinem Code zu bekommen:

<samlp:Response 
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" 
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" 
    ID="new id" 
    InResponseTo="old id" 
    Version="2.0" 
    IssueInstant="2017-04-19T11:29:39.040Z" 
    Destination="some url"> 
    <saml:Issuer>SAMLIssuer</saml:Issuer> 
    <samlp:Status> 
     <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/> 
    </samlp:Status> 
    <saml:Assertion .... 

ohne Verwendung externer Bibliotheken oder eigene Wrapper/String-Verkettungen? Ich kann nichts in .NET 4.5 Implementierung von WIF finden, die mir helfen kann.

Antwort