gpt4 book ai didi

c# - 如何使用 ASP.NET Web API 在授权 header 中提取和验证 SAML token ?

转载 作者:太空宇宙 更新时间:2023-11-03 11:24:44 25 4
gpt4 key购买 nike

我有一个 Silverlight 应用程序,它使用 Identity Training Kit 中的 WSTrust 实现从 STS 请求 SAML token 。

private void Application_Startup(object sender, StartupEventArgs e)
{
WSTrustClient wsTrustClient = new WSTrustClient(new WSTrustBindingUsernameMixed(), new EndpointAddress("https://localhost/SecurityTokenService/Service.svc/IWSTrust13"), new UsernameCredentials("user", "password"));
wsTrustClient.IssueCompleted += new EventHandler<IssueCompletedEventArgs>(wsTrustClient_IssueCompleted);

RequestSecurityToken rst = new RequestSecurityToken()
{
AppliesTo = new EndpointAddress("https://localhost/SilverlightApplication.Web")
};

wsTrustClient.IssueAsync(rst);
}

private void wsTrustClient_IssueCompleted(object sender, IssueCompletedEventArgs e)
{
this.Resources.Add("SamlToken", e.Result);
this.RootVisual = new MainPage();
}

然后,Silverlight 应用程序将 SAML token 放入对我的 ASP.NET Web API 服务的请求的授权 header 中;再次使用相同的 WSTrust 实现。

string uri ="https://localhost/WebApi/api/resource";
WebRequest request = WebRequest.Create(uri);
request.Method = "GET";

RequestSecurityTokenResponse rstr = (RequestSecurityTokenResponse)Application.Current.Resources["SamlToken"];
request.Headers[HttpRequestHeader.Authorization] = "SAML " + rstr.RequestedSecurityToken.RawToken;

request.BeginGetResponse((result) =>
{
using (WebResponse response = request.EndGetResponse(result))
{
// Process Response
}
}, null);

首先,我的做法是否正确?其次,如果是这样,我如何让我的 ASP.NET Web API 服务检测 SAML token 并将其转换为 IClaimsPrincipal 服务器端?

最佳答案

不是 Silverlight 大师,但这里有一系列关于 WebAPI 服务和 WIF 的文章(和一些自定义类)- ASP.NET WebAPI Security 1: Introducing Thinktecture.IdentityModel.Http .

这可能有帮助?

关于c# - 如何使用 ASP.NET Web API 在授权 header 中提取和验证 SAML token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9771690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com