c# - Thinktecture - Unable to handle an encrypted SAML security token in Web API -


in .net web api, how can configure thinktechture saml2securitytokenhandler use x509 certificate handle encrypted saml2 security token (decrypt before validating).

the token encrypted identity server configuring rp use certificate encrypting.

below working configuration (without handling encrypted token) taken thinktechture samples:

  #region identityserver saml   authentication.addsaml2(                 issuerthumbprint: constants.idsrv.signingcertthumbprint,                 issuername: constants.idsrv.issueruri,                 audienceuri: constants.realm,                 certificatevalidator: x509certificatevalidator.none,                 options: authenticationoptions.forauthorizationheader(constants.idsrv.samlscheme),                 scheme: authenticationscheme.schemeonly(constants.idsrv.samlscheme));   #endregion 

to enable encrypted tokens web api, found helpful: http://www.alexthissen.nl/blogs/main/archive/2011/07/18/using-active-profile-for.aspx

towards end you'll see code setting servicetokenresolver property on configuration property of securitytokenhandlercollection using x509 certificate localmachine store. configuration property securitytokenhandlerconfiguration, 1 of parameters overload of addsaml2 extension method in authenticationconfigurationextensionscore.cs thinktecture.identitymodel source. below ended with.

var registry = new configurationbasedissuernameregistry(); registry.addtrustedissuer(constants.idsrv.signingcertthumbprint, constants.idsrv.issueruri);  var handlerconfig = new securitytokenhandlerconfiguration(); handlerconfig.audiencerestriction.allowedaudienceuris.add(new uri(constants.realm)); handlerconfig.issuernameregistry = registry; handlerconfig.certificatevalidator = getx509certificatevalidatorsetting();  x509store store = new x509store(storename.my, storelocation.localmachine); store.open(openflags.readonly); x509certificate2collection certificates = store.certificates; x509certificate2collection matchingcertificates = certificates.find(     x509findtype.findbysubjectdistinguishedname,     "cn=rptokencertificate", false); x509certificate2 certificate = certificates[0];  list<securitytoken> servicetokens = new list<securitytoken>(); servicetokens.add(new x509securitytoken(certificate)); securitytokenresolver serviceresolver =     securitytokenresolver.createdefaultsecuritytokenresolver(         servicetokens.asreadonly(), false); handlerconfig.servicetokenresolver = serviceresolver;  authentication.addsaml2(handlerconfig,      authenticationoptions.forauthorizationheader(samlscheme),      authenticationscheme.schemeonly(samlscheme)); 

hope helps.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -