Tyl*_*ler 25 .net c# rest saml wif
我在字符串中有一个SAML令牌:
<saml:Assertion xmlns:saml="..." ...> ..etc... </>
Run Code Online (Sandbox Code Playgroud)
在HttpModule中,我想将其转换为ClaimsPrincipal,以便我的服务可以将通常的Thread.CurrentPrincipal作为IClaimsPrincipal来完成.
我找到了一些诱人的网页/博客/等...看起来很有帮助:
我实际上试图将SAML令牌转换为ClaimsPrincipal(通过SecurityToken中间步骤或直接...以任何方式开心).Cibrax的想法中的示例代码使用以下内容进行关键验证和反序列化步骤:
SecurityTokenSerializer securityTokenSerializer
= new SecurityTokenSerializerAdapter(
FederatedAuthentication.SecurityTokenHandlers,
MessageSecurityVersion.Default.SecurityVersion,
false, new SamlSerializer(), null, null);
SecurityToken theToken
= WSFederationAuthenticationModule.GetSecurityToken(
theSamlTokenInStringForm, securityTokenSerializer);
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,WIF的RTM版本没有公开GetSecurityToken的这个重载...它只暴露:
WSFederationAuthenticationModule fam = new WSFederationAuthenticationModule();
SecurityToken theToken = fam.GetSecurityToken(HttpRequest theRequest);
SecurityToken theToken = fam.GetSecurityToken(SignInResponseMessage message);
Run Code Online (Sandbox Code Playgroud)
谢谢你帮我搞砸了!
泰勒
Microsoft.IdentityModel.Configuration.ServiceConfiguration serviceConfig
= new Microsoft.IdentityModel.Configuration.ServiceConfiguration();
// Now read the token and convert it to an IPrincipal
SecurityToken theToken = null;
ClaimsIdentityCollection claimsIdentity = null;
using (XmlReader reader = XmlReader.Create(new StringReader(authSamlString)))
{
theToken = serviceConfig.SecurityTokenHandlers.ReadToken(reader);
claimsIdentity = serviceConfig.SecurityTokenHandlers.ValidateToken(theToken);
}
IPrincipal principal = new ClaimsPrincipal(claimsIdentity);
Run Code Online (Sandbox Code Playgroud)
我现在在向导生成的 REST 服务主机分配中遇到异常:
<%@ ServiceHost Language="C#" Debug="true" Service="Sample.RestService.Service" Factory="Sample.RestService.AppServiceHostFactory"%>
using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Microsoft.ServiceModel.Web.SpecializedServices;
namespace Sample.RestService
{
class AppServiceHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
/// ***** The exception occurs on the next line *****
return new SingletonServiceHost(serviceType, baseAddresses);
}
}
}
Run Code Online (Sandbox Code Playgroud)
异常详细信息:
System.Configuration.ConfigurationErrorsException occurred
Message="This element is not currently associated with any context"
Source="System.Configuration"
BareMessage="This element is not currently associated with any context"
Line=0
StackTrace:
at System.Configuration.ConfigurationElement.get_EvaluationContext()
InnerException: {{NONE}}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15939 次 |
| 最近记录: |