protected void Page_Load(object sender, EventArgs e) { SSOLoginData ssoLoginData = new SSOLoginData() { }; var samlRequestData = SAML2Helper.GetSamlBase64StringToGetToken(ssoLoginData); Response.Clear(); string postbackUrl = ""; var SAMLRequest = ""; var RelayState = ""; var id = ""; StringBuilder sb = new StringBuilder(); sb.Append("<html>"); sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>"); sb.AppendFormat("<form name='form' action='{0}' method='post'>", postbackUrl); sb.AppendFormat("<input type='hidden' name='SAMLRequest' value='{0}'>", SAMLRequest); sb.AppendFormat("<input type='hidden' name='RelayState' value='{0}'>", RelayState); sb.AppendFormat("<input type='hidden' name='id' value='{0}'>", id); // Other params go here sb.Append("</form>"); sb.Append("</body>"); sb.Append("</html>"); Response.Write(sb.ToString()); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { try { //var userData = db.GetSSOLoginDetail(LoggedInAgentID).FirstOrDefault(); //if (userData == null) // return; var ssoLoginData = new SSOLoginData(); //ssoLoginData.Email = userData.PrimaryEmail; //ssoLoginData.AdditionalEmail1 = userData.SecondaryEmail; //ssoLoginData.AdditionalEmail2 = userData.SalesRadixEmail; //ssoLoginData.FirstName = userData.FirstName; //ssoLoginData.LastName = userData.LastName; //ssoLoginData.RoleId = userData.Role_ID; //ssoLoginData.GlobalUserId = userData.GlobalUserId; //ssoLoginData.ManagerGlobalUserId = userData.ManagerGlobalUserId; var tokenData = GetAuthenticationToken(ssoLoginData); if (!string.IsNullOrWhiteSpace(tokenData)) { var encoding = new UnicodeEncoding(); var bytes = encoding.GetBytes(tokenData); // PortalTokenData.Value = Convert.ToBase64String(bytes); } } catch (Exception ex) { // Logger.Log(ex); } finally { string portalAuthUrl = $"{ConfigurationManager.AppSettings["PortalURL"]}/ExternalLogin/Authenticate"; form1.Action = portalAuthUrl; } }
protected void Page_Load(object sender, EventArgs e) { SSOLoginData ssoLoginData = new SSOLoginData() { Email = "*****@*****.**", City = "New York", Country = "US", Department = "IT", ErrorUrl = "https://errorsite.com/errorpage.aspx", FirstName = "John", LastName = "Smith", PhoneNumber = "001354534643", GroupMembership = "" }; var samlRequestData = SAML2Helper.GetSamlBase64StringToGetToken(ssoLoginData); Response.Clear(); string postbackUrl = "https://dev.axco.co.uk/Axco.sso/saml2/v1/signin/community"; var RelayState = "https://dev.axco.co.uk/Axco.sso/saml2/v1/signin/community"; var id = Guid.NewGuid().ToString(); StringBuilder sb = new StringBuilder(); sb.Append("<html>"); sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>"); sb.AppendFormat("<form name='form' action='{0}' method='POST'>", postbackUrl); sb.AppendFormat("<input type='hidden' id='SAMLRequest' name='SAMLRequest' value='{0}'>", samlRequestData); sb.AppendFormat("<input type='hidden' id='RelayState' name='RelayState' value='{0}'>", RelayState); sb.AppendFormat("<input type='hidden' id='id' name='id' value='{0}'>", id); // Other params go here sb.Append("</form>"); sb.Append("</body>"); sb.Append("</html>"); Response.Write(sb.ToString()); Response.End(); }
private string GetAuthenticationToken(SSOLoginData ssoLoginData) { string portalAPIUrl = $"{ConfigurationManager.AppSettings["PortalAPIURL"]}/api/auth/token"; var samlRequestData = SAML2Helper.GetSamlBase64StringToGetToken(ssoLoginData); var client = new HttpClient(); var postData = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("grant_type", "password"), // new KeyValuePair<string, string>("username", ssoLoginData.GlobalUserId.ToString()), new KeyValuePair <string, string>("password", samlRequestData), new KeyValuePair <string, string>("scope", "ssorequest") }; var response = client.PostAsync(portalAPIUrl, new FormUrlEncodedContent(postData)).Result; if (!response.IsSuccessStatusCode) { return(null); } return(response.Content.ReadAsStringAsync().Result); }
protected void btnTestSSO_Click(object sender, EventArgs e) { SSOLoginData ssoLoginData = new SSOLoginData() { Email = "*****@*****.**", UserName = "******", City = "New York", Country = "US", Department = "IT", ErrorUrl = "https://errorsite.com/errorpage.aspx", FirstName = "John", LastName = "Smith", PhoneNumber = "001354534643", GroupMembership = "InsightCompliance" }; var SAMLResponse = SAML2Helper.GetSamlBase64StringToGetToken(ssoLoginData); Response.Clear(); string postbackUrl = "https://dev.axco.co.uk/Axco.sso/saml2/v1/signin/AssurexGlobal"; var RelayState = ""; StringBuilder sb = new StringBuilder(); sb.Append("<html>"); sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>"); sb.AppendFormat("<form name='form' action='{0}' method='POST'>", postbackUrl); sb.AppendFormat("<input type='hidden' id='SAMLResponse' name='SAMLResponse' value='{0}'>", SAMLResponse); sb.AppendFormat("<input type='hidden' id='RelayState' name='RelayState' value='{0}'>", RelayState); sb.Append("</form>"); sb.Append("</body>"); sb.Append("</html>"); Response.Write(sb.ToString()); Response.End(); }