protected void btnLogin_Click(object sender, EventArgs e) { lblError.Visible = false; //Get the supplied portal username string portalUserName = tbUserName.Text; //Create a SOAP envelope to request a portal security token, POST it to the Concierge API and get the response using (HttpWebResponse response = ConciergeApiHelper.PostPortalSecurityTokenRequest(portalUserName)) { //Get a stream containing the response SOAP envelope using (Stream receiveStream = response.GetResponseStream()) { //If there was no response show a friendly error message - should not happen if (receiveStream == null) { lblError.Text = "Unable to read response from Concierge API"; lblError.Visible = true; return; } //Read the SOAP response in to an XDocument to make it easier to navigate Encoding encode = Encoding.GetEncoding("utf-8"); StreamReader responseStream = new StreamReader(receiveStream, encode); XDocument soapResponse = XDocument.Load(responseStream); //Get a table containing the namespaces and aliases we will use in our XPath to retreive values from the response XmlNamespaceManager namespaceManager = ConciergeApiHelper.CreateNamespaceManager(); //Use XPath to check if the Concierge API indicates the request was processed successfully. If it was not, display a friendly error massage if (soapResponse.XPathSelectElement("//mc:CreatePortalSecurityTokenResult/r:Success", namespaceManager).Value != "true") { lblError.Text = "Portal token generation failed."; lblError.Visible = true; XElement firstError = soapResponse.XPathSelectElement("//mc:CreatePortalSecurityTokenResult/r:Errors/c:ConciergeError[1]/c:Message", namespaceManager); if (firstError != null) { lblError.Text += " Concierge API returned error: " + firstError.Value; } return; } //Retrieve the portal security token from the SOAP response and store it in the web user's session so it can be used by the RedirectToPortal page ConciergeApiHelper.PortalLoginToken = Convert.FromBase64String(soapResponse.XPathSelectElement("//mc:CreatePortalSecurityTokenResult/r:ResultValue", namespaceManager).Value); } } //Send the web user to the page that will construct a form and POST the portal security token to the portal's Login.aspx page Response.Redirect("~/RedirectToPortal.aspx"); }
protected void btnLogin_Click(object sender, EventArgs e) { lblError.Visible = false; //Get the supplied portal username string portalUserName = tbUserName.Text; //Generate a Digital Signature of the portal username using the Signing Certificate byte[] signature = ConciergeApiHelper.GenerateDigitalSignature(portalUserName); using (ConciergeAPIService proxy = new ConciergeAPIService()) { //Generate a header for this request using the Concierge API settings and the action to be called proxy.ConciergeRequestHeaderValue = ConciergeApiHelper.CreateRequestHeader("http://membersuite.com/contracts/IConciergeAPIService/CreatePortalSecurityToken"); //Request a portal security token from the Concierge API var portalLoginTokenResult = proxy.CreatePortalSecurityToken(portalUserName, ConciergeApiHelper.SigningCertificateId, signature); //If the Concierge API indicated a fault, write a friendly error message if (!portalLoginTokenResult.Success) { lblError.Text = portalLoginTokenResult.Errors != null && portalLoginTokenResult.Errors.Any() ? portalLoginTokenResult.Errors[0].Message : "API operation failed"; lblError.Visible = true; return; } //Set the web user's session id in their session ConciergeApiHelper.ConciergeSessionId = proxy.ConciergeResponseHeaderValue.SessionId; //Set the portal security token in the web user's session so it can be used by the RedirectToPortal page ConciergeApiHelper.PortalLoginToken = portalLoginTokenResult.ResultValue; } //Send the web user to the page that will construct a form and POST the portal security token to the portal's Login.aspx page Response.Redirect("~/RedirectToPortal.aspx"); }