/// <summary> /// This Post Action is used to Generate the AuthN Request and redirect to the B2C Login endpoint /// </summary> public IActionResult OnPost() { var options = _options.CurrentValue; var tenantId = options.Tenant.ToLower()?.Replace(".onmicrosoft.com", ""); var SamlRequest = string.Empty; string b2cloginurl = tenantId + ".b2clogin.com"; var policy = options.Policy.StartsWith("B2C_1A_") ? options.Policy : "B2C_1A_" + options.Policy; var tenant = (options.Tenant.ToLower().Contains("onmicrosoft.com") || options.Tenant.ToLower().Contains(".net")) ? options.Tenant : options.Tenant + ".onmicrosoft.com"; var dcInfo = string.IsNullOrWhiteSpace(options.DCInfo) ? string.Empty : "&" + options.DCInfo; var issuer = string.IsNullOrWhiteSpace(options.Issuer) ? SAMLHelper.GetThisURL(this) : options.Issuer; var RelayState = SAMLHelper.toB64(tenant) + "." + SAMLHelper.toB64(policy) + "." + SAMLHelper.toB64(issuer); if (!string.IsNullOrEmpty(dcInfo)) { RelayState = RelayState + "." + SAMLHelper.toB64(dcInfo); } AuthnRequest AuthnReq; var URL = "https://" + b2cloginurl + "/" + tenant + "/" + policy + "/samlp/sso/login?" + dcInfo; AuthnReq = new AuthnRequest(URL, SAMLHelper.GetThisURL(this), issuer); var cdoc = SAMLHelper.Compress(AuthnReq.ToString()); URL = URL + "&SAMLRequest=" + System.Web.HttpUtility.UrlEncode(cdoc) + "&RelayState=" + System.Web.HttpUtility.UrlEncode(RelayState); return(Redirect(URL)); }
/// <summary> /// This Post Action is used to Generate the AuthN Request and redirect to the B2C Login endpoint /// </summary> public IActionResult OnPost(string Tenant, string Policy, string Issuer, string DCInfo, bool IsAzureAD) { if (string.IsNullOrEmpty(Policy) || IsAzureAD) { return(SendAzureAdRequest(Tenant)); } String TenantId = Tenant.ToLower()?.Replace(".onmicrosoft.com", ""); string SamlRequest = string.Empty; string b2cloginurl = TenantId + ".b2clogin.com"; Policy = Policy.StartsWith("B2C_1A_") ? Policy : "B2C_1A_" + Policy; Tenant = (Tenant.ToLower().Contains("onmicrosoft.com") || Tenant.ToLower().Contains(".net")) ? Tenant : Tenant + ".onmicrosoft.com"; DCInfo = string.IsNullOrWhiteSpace(DCInfo) ? string.Empty : "&" + DCInfo; Issuer = string.IsNullOrWhiteSpace(Issuer) ? SAMLHelper.GetThisURL(this) : Issuer; string RelayState = SAMLHelper.toB64(Tenant) + "." + SAMLHelper.toB64(Policy) + "." + SAMLHelper.toB64(Issuer); if (!string.IsNullOrEmpty(DCInfo)) { RelayState = RelayState + "." + SAMLHelper.toB64(DCInfo); } AuthnRequest AuthnReq; string URL = "https://" + b2cloginurl + "/" + Tenant + "/" + Policy + "/samlp/sso/login?" + DCInfo; AuthnReq = new AuthnRequest(URL, SAMLHelper.GetThisURL(this), Issuer); string cdoc = SAMLHelper.Compress(AuthnReq.ToString()); URL = URL + "&SAMLRequest=" + System.Web.HttpUtility.UrlEncode(cdoc) + "&RelayState=" + System.Web.HttpUtility.UrlEncode(RelayState); return(Redirect(URL)); }
/// <summary> /// This Post Action is used to Generate the AuthN Request and redirect to the B2C Login endpoint /// </summary> public IActionResult OnPost(string Tenant, string Policy, string Issuer, string DCInfo, bool IsAzureAD) { if (string.IsNullOrEmpty(Policy) || IsAzureAD) { return(SendAzureAdRequest()); } var TenantId = Tenant.ToLower()?.Replace(".onmicrosoft.com", string.Empty); var b2cloginurl = TenantId + ".b2clogin.com"; Policy = Policy.StartsWith("B2C_1A_") ? Policy : "B2C_1A_" + Policy; Tenant = (Tenant.ToLower().Contains("onmicrosoft.com") || Tenant.ToLower().Contains(".net")) ? Tenant : Tenant + ".onmicrosoft.com"; DCInfo = string.IsNullOrWhiteSpace(DCInfo) ? string.Empty : "&" + DCInfo; Issuer = string.IsNullOrWhiteSpace(Issuer) ? SAMLHelper.GetThisURL(this) : Issuer; var RelayState = $"{SAMLHelper.toB64(Tenant)}.{SAMLHelper.toB64(Policy)}.{SAMLHelper.toB64(Issuer)}"; if (!string.IsNullOrEmpty(DCInfo)) { RelayState += $".{SAMLHelper.toB64(DCInfo)}"; } var URL = $"https://{b2cloginurl}/{Tenant}/{Policy}/samlp/sso/login?{DCInfo}"; var AuthnReq = new AuthnRequest(URL, SAMLHelper.GetThisURL(this), Issuer); var cdoc = SAMLHelper.Compress(AuthnReq.ToString()); URL += "&SAMLRequest=" + System.Web.HttpUtility.UrlEncode(cdoc) + "&RelayState=" + System.Web.HttpUtility.UrlEncode(RelayState); return(Redirect(URL)); }
/// <summary> /// This Post Action is used to Generate the AuthN Request and redirect to the B2C Login endpoint /// </summary> public IActionResult OnPost(string Tenant, string HostName, string Policy, string Issuer, string DCInfo, bool IsAzureAD) { if (string.IsNullOrEmpty(Policy) || IsAzureAD) { return(SendAzureAdRequest(Tenant)); } string SamlRequest = string.Empty; string b2cloginurl = HostName.ToLower(); if (!String.IsNullOrEmpty(HostName)) { b2cloginurl = HostName; } else if (!String.IsNullOrEmpty(this.Tenant) && this.Tenant.EndsWith(".onmicrosoft.com")) { string TenantName = Tenant.ToLower()?.Replace(".onmicrosoft.com", ""); b2cloginurl = TenantName + ".b2clogin.com"; } Policy = Policy.StartsWith("B2C_1A_") ? Policy : "B2C_1A_" + Policy; //Tenant = (Tenant.ToLower().Contains("onmicrosoft.com") || Tenant.ToLower().Contains(".net")) ? Tenant : Tenant + ".onmicrosoft.com"; DCInfo = string.IsNullOrWhiteSpace(DCInfo) ? string.Empty : "&" + DCInfo; Issuer = string.IsNullOrWhiteSpace(Issuer) ? SAMLHelper.GetThisURL(this) : Issuer; if (null != Tenant) { HttpContext.Session.SetString("Tenant", Tenant); } if (null != b2cloginurl) { HttpContext.Session.SetString("HostName", b2cloginurl); } if (null != Policy) { HttpContext.Session.SetString("Policy", Policy); } if (null != Issuer) { HttpContext.Session.SetString("Issuer", Issuer); } string RelayState = SAMLHelper.toB64(Tenant) + "." + SAMLHelper.toB64(Policy) + "." + SAMLHelper.toB64(Issuer); if (!string.IsNullOrEmpty(DCInfo)) { RelayState = RelayState + "." + SAMLHelper.toB64(DCInfo); } AuthnRequest AuthnReq; string URL = "https://" + b2cloginurl + "/" + Tenant + "/" + Policy + "/samlp/sso/login?" + DCInfo; AuthnReq = new AuthnRequest(URL, SAMLHelper.GetThisURL(this), Issuer); string cdoc = SAMLHelper.Compress(AuthnReq.ToString()); URL = URL + "&SAMLRequest=" + System.Web.HttpUtility.UrlEncode(cdoc) + "&RelayState=" + System.Web.HttpUtility.UrlEncode(RelayState); return(Redirect(URL)); }
public IActionResult SendAzureAdRequest() { var AuthnReq = new AuthnRequest("https://login.microsoftonline.com/00000000-0000-0000-0000-000000000000/saml2", SAMLHelper.GetThisURL(this), string.Empty); var cdoc = SAMLHelper.Compress(AuthnReq.ToString()); var URL = $"https://login.microsoftonline.com/00000000-0000-0000-0000-000000000000/saml2?SAMLRequest=" + System.Web.HttpUtility.UrlEncode(cdoc); return(Redirect(URL)); }
/// <summary> /// This Post Action is used to Generate the AuthN Request and redirect to the B2C Login endpoint /// </summary> public IActionResult OnPost(string Tenant, string Policy) { string b2cloginurl = _configuration["SAMLTEST:b2cloginurl"]; Policy = Policy.StartsWith("B2C_1A_") ? Policy : "B2C_1A_" + Policy; AuthnRequest AuthnReq = new AuthnRequest("https://" + b2cloginurl + "/te/" + Tenant + ".onmicrosoft.com/" + Policy + "/samlp/sso/login", SAMLHelper.GetThisURL(this)); string cdoc = SAMLHelper.Compress(AuthnReq.ToString()); string URL = "https://" + b2cloginurl + "/te/" + Tenant + ".onmicrosoft.com/" + Policy + "/samlp/sso/login?SAMLRequest=" + System.Web.HttpUtility.UrlEncode(cdoc); return(Redirect(URL)); }
public IActionResult SendAzureAdRequest(string Tenant) { AuthnRequest AuthnReq; AuthnReq = new AuthnRequest("https://login.microsoftonline.com/42cf448f-0704-4dd0-85b5-87e61c2804a9/saml2", SAMLHelper.GetThisURL(this), string.Empty); string cdoc = SAMLHelper.Compress(AuthnReq.ToString()); string URL = $"https://login.microsoftonline.com/42cf448f-0704-4dd0-85b5-87e61c2804a9/saml2?SAMLRequest=" + System.Web.HttpUtility.UrlEncode(cdoc); return(Redirect(URL)); }
private IActionResult RunB2CLogin(string policy, PageModel model) { var b2cloginurl = TenantId + ".b2clogin.com"; Tenant = (Tenant.ToLower().Contains("onmicrosoft.com") || Tenant.ToLower().Contains(".net")) ? Tenant : Tenant + ".onmicrosoft.com"; DCInfo = string.IsNullOrWhiteSpace(DCInfo) ? string.Empty : "&" + DCInfo; Issuer = string.IsNullOrWhiteSpace(Issuer) ? SAMLHelper.GetThisURL(model) : Issuer; var RelayState = $"{SAMLHelper.toB64(Tenant)}.{SAMLHelper.toB64(policy)}.{SAMLHelper.toB64(Issuer)}"; if (!string.IsNullOrEmpty(DCInfo)) { RelayState += "." + SAMLHelper.toB64(DCInfo); } var URL = $"https://{b2cloginurl}/{Tenant}/{policy}/samlp/sso/login?{DCInfo}"; var AuthnReq = new AuthnRequest(URL, SAMLHelper.GetThisURL(model), Issuer); var cdoc = SAMLHelper.Compress(AuthnReq.ToString()); URL += "&SAMLRequest=" + HttpUtility.UrlEncode(cdoc) + "&RelayState=" + HttpUtility.UrlEncode(RelayState); return(Redirect(URL)); }