@@ -24,29 +24,21 @@ public abstract class BaseResponse
2424
2525 public string Xml { get { return _xmlDoc . OuterXml ; } }
2626
27- public BaseResponse ( string certificateStr , string responseString )
28- : this ( Encoding . ASCII . GetBytes ( certificateStr ) , responseString ) { }
27+ public BaseResponse ( string certificateStr , string responseString = null ) : this ( Encoding . ASCII . GetBytes ( certificateStr ) , responseString ) { }
2928
30- public BaseResponse ( byte [ ] certificateBytes , string responseString ) : this ( certificateBytes )
31- {
32- LoadXmlFromBase64 ( responseString ) ;
33- }
34-
35- public BaseResponse ( string certificateStr ) : this ( Encoding . ASCII . GetBytes ( certificateStr ) ) { }
36-
37- public BaseResponse ( byte [ ] certificateBytes )
29+ public BaseResponse ( byte [ ] certificateBytes , string responseString = null )
3830 {
3931 _certificate = new X509Certificate2 ( certificateBytes ) ;
40- }
32+ if ( responseString != null )
33+ LoadXmlFromBase64 ( responseString ) ;
34+ }
4135
4236 /// <summary>
4337 /// Parse SAML response XML (in case was it not passed in constructor)
4438 /// </summary>
4539 public void LoadXml ( string xml )
4640 {
47- _xmlDoc = new XmlDocument ( ) ;
48- _xmlDoc . PreserveWhitespace = true ;
49- _xmlDoc . XmlResolver = null ;
41+ _xmlDoc = new XmlDocument { PreserveWhitespace = true , XmlResolver = null } ;
5042 _xmlDoc . LoadXml ( xml ) ;
5143
5244 _xmlNameSpaceManager = GetNamespaceManager ( ) ; //lets construct a "manager" for XPath queries
@@ -98,13 +90,9 @@ private XmlNamespaceManager GetNamespaceManager()
9890
9991 public class Response : BaseResponse
10092 {
101- public Response ( string certificateStr , string responseString ) : base ( certificateStr , responseString ) { }
102-
103- public Response ( byte [ ] certificateBytes , string responseString ) : base ( certificateBytes , responseString ) { }
104-
105- public Response ( string certificateStr ) : base ( certificateStr ) { }
93+ public Response ( string certificateStr , string responseString = null ) : base ( certificateStr , responseString ) { }
10694
107- public Response ( byte [ ] certificateBytes ) : base ( certificateBytes ) { }
95+ public Response ( byte [ ] certificateBytes , string responseString = null ) : base ( certificateBytes , responseString ) { }
10896
10997 /// <summary>
11098 /// Checks the validity of SAML response (validate signature, check expiration date etc)
@@ -198,36 +186,32 @@ public virtual string GetLocation()
198186 public string GetCustomAttribute ( string attr )
199187 {
200188 XmlNode node = _xmlDoc . SelectSingleNode ( "/samlp:Response/saml:Assertion[1]/saml:AttributeStatement/saml:Attribute[@Name='" + attr + "']/saml:AttributeValue" , _xmlNameSpaceManager ) ;
201- return node == null ? null : node . InnerText ;
189+ return node ? . InnerText ;
202190 }
203191
204192 public string GetCustomAttributeViaFriendlyName ( string attr )
205193 {
206194 XmlNode node = _xmlDoc . SelectSingleNode ( "/samlp:Response/saml:Assertion[1]/saml:AttributeStatement/saml:Attribute[@FriendlyName='" + attr + "']/saml:AttributeValue" , _xmlNameSpaceManager ) ;
207- return node == null ? null : node . InnerText ;
195+ return node ? . InnerText ;
208196 }
209197
210198 public List < string > GetCustomAttributeAsList ( string attr )
211199 {
212200 XmlNodeList nodes = _xmlDoc . SelectNodes ( "/samlp:Response/saml:Assertion[1]/saml:AttributeStatement/saml:Attribute[@Name='" + attr + "']/saml:AttributeValue" , _xmlNameSpaceManager ) ;
213- return nodes == null ? null : nodes . Cast < XmlNode > ( ) . Select ( x => x . InnerText ) . ToList ( ) ;
201+ return nodes ? . Cast < XmlNode > ( ) . Select ( x => x . InnerText ) . ToList ( ) ;
214202 }
215203 }
216204
217205 public class SignoutResponse : BaseResponse
218206 {
219- public SignoutResponse ( string certificateStr , string responseString ) : base ( certificateStr , responseString ) { }
220-
221- public SignoutResponse ( byte [ ] certificateBytes , string responseString ) : base ( certificateBytes , responseString ) { }
222-
223- public SignoutResponse ( string certificateStr ) : base ( certificateStr ) { }
207+ public SignoutResponse ( string certificateStr , string responseString = null ) : base ( certificateStr , responseString ) { }
224208
225- public SignoutResponse ( byte [ ] certificateBytes ) : base ( certificateBytes ) { }
209+ public SignoutResponse ( byte [ ] certificateBytes , string responseString = null ) : base ( certificateBytes , responseString ) { }
226210
227211 public string GetLogoutStatus ( )
228212 {
229213 XmlNode node = _xmlDoc . SelectSingleNode ( "/samlp:LogoutResponse/samlp:Status/samlp:StatusCode" , _xmlNameSpaceManager ) ;
230- return node == null ? null : node . Attributes [ "Value" ] . Value . Replace ( "urn:oasis:names:tc:SAML:2.0:status:" , string . Empty ) ;
214+ return node ? . Attributes [ "Value" ] . Value . Replace ( "urn:oasis:names:tc:SAML:2.0:status:" , string . Empty ) ;
231215 }
232216 }
233217
@@ -299,6 +283,7 @@ public AuthRequest(string issuer, string assertionConsumerServiceUrl) : base(iss
299283 /// </summary>
300284 public bool ForceAuthn { get ; set ; }
301285
286+ [ Obsolete ( "Obsolete, will be removed" ) ]
302287 public enum AuthRequestFormat
303288 {
304289 Base64 = 1
@@ -316,8 +301,7 @@ public override string GetRequest()
316301 {
317302 using ( StringWriter sw = new StringWriter ( ) )
318303 {
319- XmlWriterSettings xws = new XmlWriterSettings ( ) ;
320- xws . OmitXmlDeclaration = true ;
304+ XmlWriterSettings xws = new XmlWriterSettings { OmitXmlDeclaration = true } ;
321305
322306 using ( XmlWriter xw = XmlWriter . Create ( sw , xws ) )
323307 {
@@ -367,8 +351,7 @@ public override string GetRequest()
367351 {
368352 using ( StringWriter sw = new StringWriter ( ) )
369353 {
370- XmlWriterSettings xws = new XmlWriterSettings ( ) ;
371- xws . OmitXmlDeclaration = true ;
354+ XmlWriterSettings xws = new XmlWriterSettings { OmitXmlDeclaration = true } ;
372355
373356 using ( XmlWriter xw = XmlWriter . Create ( sw , xws ) )
374357 {
0 commit comments