Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SendWithNtAuthAsync()

static async Task< HttpResponseMessage > System.Net.Http.AuthenticationHelper.SendWithNtAuthAsync ( HttpRequestMessage request,
Uri authUri,
bool async,
ICredentials credentials,
bool isProxyAuth,
HttpConnection connection,
HttpConnectionPool connectionPool,
CancellationToken cancellationToken )
inlinestaticprivate

Definition at line 633 of file AuthenticationHelper.cs.

634 {
636 if (!isProxyAuth && connection.Kind == HttpConnectionKind.Proxy && !ProxySupportsConnectionAuth(response))
637 {
638 if (System.Net.NetEventSource.Log.IsEnabled())
639 {
640 System.Net.NetEventSource.Error(connection, $"Proxy doesn't support connection-based auth, uri={authUri}", "SendWithNtAuthAsync");
641 }
642 return response;
643 }
644 if (TryGetAuthenticationChallenge(response, isProxyAuth, authUri, credentials, out var challenge) && (challenge.AuthenticationType == AuthenticationType.Negotiate || challenge.AuthenticationType == AuthenticationType.Ntlm))
645 {
646 bool isNewConnection = false;
647 bool needDrain = true;
648 try
649 {
650 if (response.Headers.ConnectionClose.GetValueOrDefault())
651 {
652 connection.DetachFromPool();
653 connection = await connectionPool.CreateHttp11ConnectionAsync(request, async, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
654 connection.Acquire();
655 isNewConnection = true;
656 needDrain = false;
657 }
658 if (System.Net.NetEventSource.Log.IsEnabled())
659 {
660 System.Net.NetEventSource.Info(connection, $"Authentication: {challenge.AuthenticationType}, Uri: {authUri.AbsoluteUri}", "SendWithNtAuthAsync");
661 }
662 string text;
663 if (!isProxyAuth && request.HasHeaders && request.Headers.Host != null)
664 {
665 text = request.Headers.Host;
666 if (System.Net.NetEventSource.Log.IsEnabled())
667 {
668 System.Net.NetEventSource.Info(connection, $"Authentication: {challenge.AuthenticationType}, Host: {text}", "SendWithNtAuthAsync");
669 }
670 }
671 else
672 {
673 UriHostNameType hostNameType = authUri.HostNameType;
674 text = ((hostNameType != UriHostNameType.IPv6 && hostNameType != UriHostNameType.IPv4) ? (await Dns.GetHostEntryAsync(authUri.IdnHost, cancellationToken).ConfigureAwait(continueOnCapturedContext: false)).HostName : authUri.IdnHost);
675 if (!isProxyAuth && !authUri.IsDefaultPort && UsePortInSpn)
676 {
677 IFormatProvider formatProvider = null;
678 IFormatProvider provider = formatProvider;
681 handler.AppendFormatted(text);
682 handler.AppendLiteral(":");
683 handler.AppendFormatted(authUri.Port);
684 text = string.Create(provider, initialBuffer, ref handler);
685 }
686 }
687 string text2 = "HTTP/" + text;
688 if (System.Net.NetEventSource.Log.IsEnabled())
689 {
690 System.Net.NetEventSource.Info(connection, $"Authentication: {challenge.AuthenticationType}, SPN: {text2}", "SendWithNtAuthAsync");
691 }
692 ChannelBinding channelBinding = connection.TransportContext?.GetChannelBinding(ChannelBindingKind.Endpoint);
694 string challengeData = challenge.ChallengeData;
695 try
696 {
697 while (true)
698 {
699 string challengeResponse = authContext.GetOutgoingBlob(challengeData);
700 if (challengeResponse != null)
701 {
702 if (needDrain)
703 {
704 await connection.DrainResponseAsync(response, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
705 }
709 {
710 needDrain = true;
711 continue;
712 }
713 break;
714 }
715 break;
716 }
717 }
718 finally
719 {
720 authContext.CloseContext();
721 }
722 }
723 finally
724 {
725 if (isNewConnection)
726 {
727 connection.Release();
728 }
729 }
730 }
731 return response;
732 }
static ValueTask< HttpResponseMessage > InnerSendAsync(HttpRequestMessage request, bool async, bool isProxyAuth, bool doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)
static bool TryGetAuthenticationChallenge(HttpResponseMessage response, bool isProxyAuth, Uri authUri, ICredentials credentials, out AuthenticationChallenge challenge)
static void SetRequestAuthenticationHeaderValue(HttpRequestMessage request, AuthenticationHeaderValue headerValue, bool isProxyAuth)
static bool TryGetRepeatedChallenge(HttpResponseMessage response, string scheme, bool isProxyAuth, out string challengeData)
static bool ProxySupportsConnectionAuth(HttpResponseMessage response)
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)

References System.Net.Http.HttpConnection.Acquire(), System.Runtime.CompilerServices.DefaultInterpolatedStringHandler.AppendFormatted(), System.Runtime.CompilerServices.DefaultInterpolatedStringHandler.AppendLiteral(), System.cancellationToken, System.Net.Http.HttpConnection.DetachFromPool(), System.Net.Http.HttpConnection.DrainResponseAsync(), System.Net.NetEventSource.Error(), System.Net.TransportContext.GetChannelBinding(), System.Net.Dns.GetHostEntryAsync(), System.Net.NetEventSource.Info(), System.Net.Http.AuthenticationHelper.InnerSendAsync(), System.Net.Http.HttpConnection.Kind, System.Net.NetEventSource.Log, System.Net.Http.AuthenticationHelper.ProxySupportsConnectionAuth(), System.Net.Http.HttpConnection.Release(), System.Net.Http.AuthenticationHelper.SetRequestAuthenticationHeaderValue(), System.text, System.Net.Http.HttpConnection.TransportContext, System.Net.Http.AuthenticationHelper.TryGetAuthenticationChallenge(), System.Net.Http.AuthenticationHelper.TryGetRepeatedChallenge(), and System.Net.Http.AuthenticationHelper.UsePortInSpn.

Referenced by System.Net.Http.AuthenticationHelper.SendWithNtConnectionAuthAsync(), and System.Net.Http.AuthenticationHelper.SendWithNtProxyAuthAsync().