Hi Guys,
I have written a sample web page that gets hold of the SAML token from https://myclientssp2010.domain.com/affwebservices/public/wsfeddispatcher? after successfully authenticating with SiteMinder (got the SMSESSION cookie). Then I build the post data using the following statement:
url = domain + "/_trust/default.aspx";
namevalues = GetHTMLInputTags(ResponseToString(response));
string stringData = String.Format("wctx={0}&wresult={1}&wa=wsignin1.0",
HttpUtility.UrlEncode(namevalues["Wctx"]),
HttpUtility.UrlEncode(namevalues["wresult"]));
HttpWebRequest sharepointRequest = HttpWebRequest.Create(url) as HttpWebRequest;
message += string.Format("Programmatic Post to URL = {0}<br/>", sharepointRequest.RequestUri);
message += string.Format("Post Data = {0}<br/><br/>", stringData);
sharepointRequest.Method = "POST";
sharepointRequest.ContentType = "application/x-www-form-urlencoded";
sharepointRequest.CookieContainer = cookies;
sharepointRequest.UserAgent = userAgent;
sharepointRequest.AllowAutoRedirect = false; // This is important
Stream newStream = sharepointRequest.GetRequestStream();
byte[] data = Encoding.UTF8.GetBytes(stringData);
newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse webResponse = sharepointRequest.GetResponse() as HttpWebResponse;
string fedCookie = webResponse.Cookies["FedAuth"].Value;
Executing the above block, I get the following exception at the statement sharepointRequest.GetResponse().
The token '"' was expected but found '&'. Line 1, position 37.
Stack Trace:
[XmlException: The token '"' was expected but found '&'. Line 1, position 37.]
System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3) +689154
System.Xml.XmlUTF8TextReader.ReadAttributes() +2012212
System.Xml.XmlUTF8TextReader.ReadStartElement() +285
System.Xml.XmlUTF8TextReader.Read() +198
System.Xml.XmlBaseReader.MoveToContent() +30
Microsoft.IdentityModel.Protocols.WSFederation.WSFederationSerializer..ctor(XmlDictionaryReader reader) +37
Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.CreateSerializerForResultXml(String resultXml) +197
Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.GetXmlTokenFromMessage(SignInResponseMessage message) +67
Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.GetSecurityToken(SignInResponseMessage message) +36
Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequest request) +312
Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args) +1087222
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171