/// <summary> /// Function that parses the RSTR from Windows Live and pulls out all the important pieces /// of data from it. /// </summary> /// <param name="rstResponse">The RSTR, positioned at the beginning of the SOAP body.</param> private void ParseWindowsLiveRSTResponseBody(EwsXmlReader rstResponse) { // Read the WS-Trust RequestSecurityTokenResponseCollection node. rstResponse.ReadStartElement( XmlNamespace.WSTrustFebruary2005, RequestSecurityTokenResponseCollectionElementName); // Skip the first token - our interest is in the second token (the service token). rstResponse.SkipElement( XmlNamespace.WSTrustFebruary2005, RequestSecurityTokenResponseElementName); // Now process the second token. rstResponse.ReadStartElement( XmlNamespace.WSTrustFebruary2005, RequestSecurityTokenResponseElementName); while (!rstResponse.IsEndElement( XmlNamespace.WSTrustFebruary2005, RequestSecurityTokenResponseElementName)) { // Watch for the EncryptedData element - when we find it, parse out the appropriate bits of data. // // Also watch for the "pp" element in the Passport SOAP fault namespace, which indicates that // something went wrong with the token request. If we find it, trace and throw accordingly. if (rstResponse.IsStartElement() && (rstResponse.LocalName == EncryptedDataElementName) && (rstResponse.NamespaceUri == XmlEncNamespace)) { this.SecurityToken = rstResponse.ReadOuterXml(); } else if (rstResponse.IsStartElement(XmlNamespace.PassportSoapFault, PpElementName)) { if (this.TraceEnabled) { string logMessage = string.Format( "Windows Live reported an error retrieving the token - {0}", rstResponse.ReadOuterXml()); this.traceListener.Trace("WindowsLiveResponse", logMessage); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, EncryptedDataElementName)); } // Move to the next bit of data... rstResponse.Read(); } // If we didn't find the token, throw. if (this.SecurityToken == null) { if (this.TraceEnabled) { string logMessage = string.Format( "Did not find all required parts of the Windows Live response - " + "Security Token - {0}", (this.SecurityToken == null) ? "NOT FOUND" : "found"); this.traceListener.Trace("WindowsLiveResponse", logMessage); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, "No security token found.")); } // Read past the RequestSecurityTokenResponseCollection end element. rstResponse.Read(); }
/// <summary> /// Function that parses the RSTR from Windows Live and pulls out all the important pieces /// of data from it. /// </summary> /// <param name="rstResponse">The RSTR, positioned at the beginning of the SOAP body.</param> /* private */ void ParseWindowsLiveRSTResponseBody(EwsXmlReader rstResponse) { // Read the WS-Trust RequestSecurityTokenResponseCollection node. rstResponse.ReadStartElement( XmlNamespace.WSTrustFebruary2005, RequestSecurityTokenResponseCollectionElementName); // Skip the first token - our interest is in the second token (the service token). rstResponse.SkipElement( XmlNamespace.WSTrustFebruary2005, RequestSecurityTokenResponseElementName); // Now process the second token. rstResponse.ReadStartElement( XmlNamespace.WSTrustFebruary2005, RequestSecurityTokenResponseElementName); while (!rstResponse.IsEndElement( XmlNamespace.WSTrustFebruary2005, RequestSecurityTokenResponseElementName)) { // Watch for the EncryptedData element - when we find it, parse out the appropriate bits of data. // // Also watch for the "pp" element in the Passport SOAP fault namespace, which indicates that // something went wrong with the token request. If we find it, trace and throw accordingly. if (rstResponse.IsStartElement() && (rstResponse.LocalName == EncryptedDataElementName) && (rstResponse.NamespaceUri == XmlEncNamespace)) { this.SecurityToken = rstResponse.ReadOuterXml(); } else if (rstResponse.IsStartElement(XmlNamespace.PassportSoapFault, PpElementName)) { if (this.TraceEnabled) { String logMessage = string.Format( "Windows Live reported an error retrieving the token - {0}", rstResponse.ReadOuterXml()); this.traceListener.Trace("WindowsLiveResponse", logMessage); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, EncryptedDataElementName)); } // Move to the next bit of data... rstResponse.Read(); } // If we didn't find the token, throw. if (this.SecurityToken == null) { if (this.TraceEnabled) { String logMessage = string.Format( "Did not find all required parts of the Windows Live response - " + "Security Token - {0}", (this.SecurityToken == null) ? "NOT FOUND" : "found"); this.traceListener.Trace("WindowsLiveResponse", logMessage); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, "No security token found.")); } // Read past the RequestSecurityTokenResponseCollection end element. rstResponse.Read(); }