コード例 #1
0
        public void TryThrottle(AuthenticationRequestParameters requestParams, IReadOnlyDictionary <string, string> bodyParams)
        {
            if (!ThrottlingCache.IsEmpty() &&
                ThrottleCommon.IsRetryAfterAndHttpStatusThrottlingSupported(requestParams))
            {
                var logger = requestParams.RequestContext.Logger;

                string strictThumbprint = ThrottleCommon.GetRequestStrictThumbprint(
                    bodyParams,
                    requestParams.AuthorityInfo.CanonicalAuthority,
                    requestParams.Account?.HomeAccountId?.Identifier);

                ThrottleCommon.TryThrow(strictThumbprint, ThrottlingCache, logger, nameof(HttpStatusProvider));
            }
        }
        public void RecordException(
            AuthenticationRequestParameters requestParams,
            IReadOnlyDictionary <string, string> bodyParams,
            MsalServiceException ex)
        {
            if (TryGetRetryAfterValue(ex.Headers, out TimeSpan retryAfterTimespan))
            {
                retryAfterTimespan = GetSafeValue(retryAfterTimespan);

                var logger = requestParams.RequestContext.Logger;
                logger.Info($"[Throttling] Retry-After header detected, " +
                            $"value: {retryAfterTimespan.TotalSeconds} seconds");

                string thumbprint = ThrottleCommon.GetRequestStrictThumbprint(
                    bodyParams,
                    requestParams.AuthorityInfo.CanonicalAuthority,
                    requestParams.Account?.HomeAccountId?.Identifier);
                var entry = new ThrottlingCacheEntry(ex, retryAfterTimespan);

                ThrottlingCache.AddAndCleanup(thumbprint, entry, logger);
            }
        }
コード例 #3
0
        public void RecordException(
            AuthenticationRequestParameters requestParams,
            IReadOnlyDictionary <string, string> bodyParams,
            MsalServiceException ex)
        {
            var logger = requestParams.RequestContext.Logger;

            if (ThrottleCommon.IsRetryAfterAndHttpStatusThrottlingSupported(requestParams) &&
                (ex.StatusCode == 429 || (ex.StatusCode >= 500 && ex.StatusCode < 600)) &&
                // if a retry-after header is present, another provider will take care of this
                !RetryAfterProvider.TryGetRetryAfterValue(ex.Headers, out _))
            {
                logger.Info($"[Throttling] Http status code {ex.StatusCode} encountered - " +
                            $"throttling for {s_throttleDuration.TotalSeconds} seconds");

                var thumbprint = ThrottleCommon.GetRequestStrictThumbprint(bodyParams,
                                                                           requestParams.AuthorityInfo.CanonicalAuthority,
                                                                           requestParams.Account?.HomeAccountId?.Identifier);
                var entry = new ThrottlingCacheEntry(ex, s_throttleDuration);
                ThrottlingCache.AddAndCleanup(thumbprint, entry, logger);
            }
        }