コード例 #1
0
        public BearerTokenValidator(IConfiguration configuration, ILogger <BearerTokenValidator> logger)
        {
            _asyncExpiringLazy = new AsyncExpiringLazy <OpenIdConnectConfiguration>(ValueProvider);

            _configuration = configuration;

            _logger = logger;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ResilientStreamingClient"/> class.
        /// </summary>
        /// <param name="tokenResponse"></param>
        /// <param name="options"></param>
        /// <param name="logger"></param>
        public ResilientStreamingClient(
            Func <AsyncExpiringLazy <AccessTokenResponse> > tokenResponse,
            IOptions <SalesforceConfiguration> options,
            ILogger <ResilientStreamingClient> logger)
        {
            _logger        = logger;
            _options       = options.Value;
            _tokenResponse = tokenResponse();

            CreateBayeuxClient();
        }
コード例 #3
0
        public async Task End2End()
        {
            var testInstance = new AsyncExpiringLazy <TokenResponse>(async metadata =>
            {
                await Task.Delay(1000);
                return(new ExpirationMetadata <TokenResponse>
                {
                    Result = new TokenResponse
                    {
                        AccessToken = Guid.NewGuid().ToString()
                    }, ValidUntil = DateTimeOffset.UtcNow.AddSeconds(2)
                });
            });

            // 1. check if value is created - shouldn't
            Assert.False(await testInstance.IsValueCreated());

            // 2. fetch lazy expiring value
            var token = await testInstance.Value();

            // 3a. verify it is created now
            Assert.True(await testInstance.IsValueCreated());

            // 3b. verify it is not null
            Assert.NotNull(token.AccessToken);

            // 4. fetch the value again. Since it's lifetime is 2 seconds, it should be still the same
            var token2 = await testInstance.Value();

            Assert.Same(token, token2);

            // 5. sleep for 2 seconds to let the value expire
            await Task.Delay(2000);

            // 6a. verify the value expired
            Assert.False(await testInstance.IsValueCreated());

            // 6b. fetch again
            var token3 = await testInstance.Value();

            // 7. verify we now have a new (recreated) value - as the previous one expired
            Assert.NotSame(token2, token3);

            // 8. invalidate the value manually before it has a chance to expire
            await testInstance.Invalidate();

            // 9. check if value is created - shouldn't anymore
            Assert.False(await testInstance.IsValueCreated());
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResilientForceClient"/> class.
        /// </summary>
        /// <param name="forceClient"></param>
        /// <param name="options"></param>
        /// <param name="logger"></param>
        public ResilientForceClient(
            Func <AsyncExpiringLazy <ForceClient> > forceClient,
            IOptions <SalesforceConfiguration> options,
            ILogger <ResilientForceClient> logger)
        {
            if (forceClient == null)
            {
                throw new ArgumentNullException(nameof(forceClient));
            }

            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            _forceClient = forceClient();
            _options     = options.Value;

            _policy = Policy.WrapAsync(GetAuthenticationRetryPolicy(), GetWaitAndRetryPolicy());
        }