private static AntiForgeryWorker CreateSingletonAntiForgeryWorker() { IAntiForgeryConfig config = new AntiForgeryConfigWrapper(); IAntiForgeryTokenSerializer serializer = new AntiForgeryTokenSerializer(MachineKey45CryptoSystem.Instance); ITokenStore tokenStore = new AntiForgeryTokenStore(config, serializer); IClaimUidExtractor claimUidExtractor = new ClaimUidExtractor(config, ClaimsIdentityConverter.Default); ITokenValidator validator = new TokenValidator(config, claimUidExtractor); return new AntiForgeryWorker(serializer, config, tokenStore, validator); }
public BinaryBlob ExtractClaimUid(IIdentity identity) { if (identity == null || !identity.IsAuthenticated || this._config.SuppressIdentityHeuristicChecks) { return(null); } ClaimsIdentity claimsIdentity = this._claimsIdentityConverter.TryConvert(identity); if (claimsIdentity == null) { return(null); } string[] uniqueIdentifierParameters = ClaimUidExtractor.GetUniqueIdentifierParameters(claimsIdentity, this._config.UniqueClaimTypeIdentifier); byte[] data = CryptoUtil.ComputeSHA256(uniqueIdentifierParameters); return(new BinaryBlob(256, data)); }
private static AntiForgeryWorker CreateSingletonAntiForgeryWorker() { // initialize the dependency chain // The 'Instance' property can return null, in which case we should fall back to using // the 4.0 crypto code paths. We need to use an 'if' block rather than the null coalescing // operator due to a CLR bug (DevDiv #424203). ICryptoSystem cryptoSystem = MachineKey45CryptoSystem.Instance; if (cryptoSystem == null) { cryptoSystem = new MachineKey40CryptoSystem(); } IAntiForgeryConfig config = new AntiForgeryConfigWrapper(); IAntiForgeryTokenSerializer serializer = new AntiForgeryTokenSerializer(cryptoSystem); ITokenStore tokenStore = new AntiForgeryTokenStore(config, serializer); IClaimUidExtractor claimUidExtractor = new ClaimUidExtractor(config, ClaimsIdentityConverter.Default); ITokenValidator tokenValidator = new TokenValidator(config, claimUidExtractor); return new AntiForgeryWorker(serializer, config, tokenStore, tokenValidator); }