Esempio n. 1
0
 /// <summary>
 /// A client side library needs to communicate to the server side that
 /// it has implemented enforcement of HTTP 429 and Retry-After header.
 /// Because if the server-side detects loops, then it can break the loop by sending
 /// either HTTP 429 or Retry-After header with a different HTTP status.
 /// Right now, the server side breaks the loops by invalid_grant response,
 /// which breaks protocol under some condition and also causes unexplained prompt.
 /// </summary>
 private void AddThrottlingHeader()
 {
     if (ThrottleCommon.IsRetryAfterAndHttpStatusThrottlingSupported(_requestParams))
     {
         _oAuth2Client.AddHeader(
             ThrottleCommon.ThrottleRetryAfterHeaderName,
             ThrottleCommon.ThrottleRetryAfterHeaderValue);
     }
 }
        private void AddBodyParamsAndHeaders(IDictionary <string, string> additionalBodyParameters, string scopes)
        {
            _oAuth2Client.AddBodyParameter(OAuth2Parameter.ClientId, _requestParams.ClientId);
            _oAuth2Client.AddBodyParameter(OAuth2Parameter.ClientInfo, "1");


#if DESKTOP || NETSTANDARD1_3 || NET_CORE
            if (_requestParams.ClientCredential != null)
            {
                Dictionary <string, string> ccBodyParameters = ClientCredentialHelper.CreateClientCredentialBodyParameters(
                    _requestParams.RequestContext.Logger,
                    _serviceBundle.PlatformProxy.CryptographyManager,
                    _requestParams.ClientCredential,
                    _requestParams.ClientId,
                    _requestParams.Endpoints,
                    _requestParams.SendX5C);

                foreach (var entry in ccBodyParameters)
                {
                    _oAuth2Client.AddBodyParameter(entry.Key, entry.Value);
                }
            }
#endif
            _oAuth2Client.AddBodyParameter(OAuth2Parameter.Scope, scopes);
            _oAuth2Client.AddBodyParameter(OAuth2Parameter.Claims, _requestParams.ClaimsAndClientCapabilities);

            foreach (var kvp in additionalBodyParameters)
            {
                _oAuth2Client.AddBodyParameter(kvp.Key, kvp.Value);
            }

            foreach (var kvp in _requestParams.AuthenticationScheme.GetTokenRequestParams())
            {
                _oAuth2Client.AddBodyParameter(kvp.Key, kvp.Value);
            }

            _oAuth2Client.AddHeader(
                TelemetryConstants.XClientCurrentTelemetry,
                _serviceBundle.HttpTelemetryManager.GetCurrentRequestHeader(
                    _requestParams.RequestContext.ApiEvent));

            if (!_requestInProgress)
            {
                _oAuth2Client.AddHeader(
                    TelemetryConstants.XClientLastTelemetry,
                    _serviceBundle.HttpTelemetryManager.GetLastRequestHeader());
                _requestInProgress = true;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// A client side library needs to communicate to the server side that
 /// it has implemented enforcement of HTTP 429 and Retry-After header.
 /// Because if the server-side detects loops, then it can break the loop by sending
 /// either HTTP 429 or Retry-After header with a different HTTP status.
 /// Right now, the server side breaks the loops by invalid_grant response,
 /// which breaks protocol under some condition and also causes unexplained prompt.
 /// </summary>
 private void AddThrottlingHeader()
 {
     _oAuth2Client.AddHeader(
         ThrottleCommon.ThrottleRetryAfterHeaderName,
         ThrottleCommon.ThrottleRetryAfterHeaderValue);
 }