У меня есть маркер SAML в строке:
..etc... >
В HttpModule я хочу преобразовать это в ClaimsPrincipal так, чтобы мой сервис мог сделать обычный Поток. 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);
Стена, в которую я врезался, - то, что версия RTM WIF не выставляет эту перегрузку GetSecurityToken... это только выставляет:
WSFederationAuthenticationModule fam = new WSFederationAuthenticationModule();
SecurityToken theToken = fam.GetSecurityToken(HttpRequest theRequest);
SecurityToken theToken = fam.GetSecurityToken(SignInResponseMessage message);
Спасибо за помощь мне быть отклеенным!
Tyler
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);
Я Теперь я получаю исключение в сгенерированном мастером распределении хоста службы 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);
}
}
}
Сведения об исключении:
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}}