SAML2使用ASP.NET与ADFS联合元数据进行身份验证

发布于 2025-01-26 01:14:34 字数 1092 浏览 2 评论 0原文

我正在尝试通过 ASP.NET Web应用程序(SP)(。Net Framework 4.0)实现SAML2身份验证,并使用ADFS(IDP)实现。我已经集成了saml2.o掘金,并尝试以多种方式从HTML表单中获取凭证输入并发布SAML响应。但是无法显示输入表格并获得SAML响应?

这是我的示例源代码:(我已经实现了HTTP Post Binding)

StringBuilder sb = new StringBuilder();
Saml20AuthnRequest samlRequest = ADFSRequest.GetDefault();
samlRequest.Request.Destination = ConfigurationManager.AppSettings["IdentityProviderUrl"];
samlRequest.Request.AssertionConsumerServiceUrl = ConfigurationManager.AppSettings["ServiceProviderUrl"];
                    sb.Append(string.Format("{0}wia?SAMLRequest=",ConfigurationManager.AppSettings["IdentityProviderUrl"]));
                    sb.Append(HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(samlRequest.GetXml().OuterXml))));
                    sb.Append("&client-request-id=").Append(samlRequest.Id);
                    HttpContext.Current.Response.Redirect(sb.ToString(),false);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();

任何人都可以帮助在ASP.NET应用程序中实现SAML2? 注意:我不想使用任何30个部分的工具,开源是可以的。

I am trying to implement the SAML2 authentication from ASP.NET Web Application(SP)(.Net Framework 4.0) with ADFS(IdP). I had integrated SAML2.o nugget and tried to many ways to get the credential inputs from HTML form and Post the SAML Response. But unable to display the input form and get the SAML Response?

Here is my sample source code : (I have implement the HTTP Post Binding)

StringBuilder sb = new StringBuilder();
Saml20AuthnRequest samlRequest = ADFSRequest.GetDefault();
samlRequest.Request.Destination = ConfigurationManager.AppSettings["IdentityProviderUrl"];
samlRequest.Request.AssertionConsumerServiceUrl = ConfigurationManager.AppSettings["ServiceProviderUrl"];
                    sb.Append(string.Format("{0}wia?SAMLRequest=",ConfigurationManager.AppSettings["IdentityProviderUrl"]));
                    sb.Append(HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(samlRequest.GetXml().OuterXml))));
                    sb.Append("&client-request-id=").Append(samlRequest.Id);
                    HttpContext.Current.Response.Redirect(sb.ToString(),false);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();

Anyone can help to implement the SAML2 in ASP.Net application?
Note: I don’t want to use any thirty-part tools and open source is fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

格子衫的從容 2025-02-02 01:14:34
                 this worked for me for azure setup

                 using (StreamReader inputStream = new StreamReader(context.Request.InputStream))
                    {
                        assertionXml = inputStream.ReadToEnd();
                    }
                    NameValueCollection formcollectiom = HttpUtility.ParseQueryString(assertionXml);
                    JObject result = new JObject();
                    try
                    {

                        string response = formcollectiom["SAMLResponse"];
                        assertionXml = System.Text.UTF8Encoding.UTF8.GetString(Convert.FromBase64String(response));
                
                        Dictionary<string, string> requestAttributes = new Dictionary<string, string>();
                        //add your custom Attributes here 
                        
                        result = SAMLHelper.verifyAssertion(assertionXml, "IDP_Issuer", consumerEndPoint, IDP_Issuer_Certificate, requestAttributes);
                       
                    }
                 this worked for me for azure setup

                 using (StreamReader inputStream = new StreamReader(context.Request.InputStream))
                    {
                        assertionXml = inputStream.ReadToEnd();
                    }
                    NameValueCollection formcollectiom = HttpUtility.ParseQueryString(assertionXml);
                    JObject result = new JObject();
                    try
                    {

                        string response = formcollectiom["SAMLResponse"];
                        assertionXml = System.Text.UTF8Encoding.UTF8.GetString(Convert.FromBase64String(response));
                
                        Dictionary<string, string> requestAttributes = new Dictionary<string, string>();
                        //add your custom Attributes here 
                        
                        result = SAMLHelper.verifyAssertion(assertionXml, "IDP_Issuer", consumerEndPoint, IDP_Issuer_Certificate, requestAttributes);
                       
                    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文