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

◆ SendWithAuthAsync()

static async ValueTask< HttpResponseMessage > System.Net.Http.AuthenticationHelper.SendWithAuthAsync ( HttpRequestMessage request,
Uri authUri,
bool async,
ICredentials credentials,
bool preAuthenticate,
bool isProxyAuth,
bool doRequestAuth,
HttpConnectionPool pool,
CancellationToken cancellationToken )
inlinestaticprivate

Definition at line 359 of file AuthenticationHelper.cs.

360 {
361 bool performedBasicPreauth = false;
362 if (preAuthenticate)
363 {
364 NetworkCredential credential;
365 lock (pool.PreAuthCredentials)
366 {
367 credential = pool.PreAuthCredentials.GetCredential(authUri, "Basic");
368 }
369 if (credential != null)
370 {
373 }
374 }
377 {
378 switch (challenge.AuthenticationType)
379 {
380 case AuthenticationType.Digest:
381 {
382 DigestResponse digestResponse = new DigestResponse(challenge.ChallengeData);
384 {
385 break;
386 }
387 response.Dispose();
390 {
391 digestResponse = new DigestResponse(challengeData);
393 bool flag2 = flag;
394 if (flag2)
395 {
397 }
398 if (flag2)
399 {
400 response.Dispose();
402 }
403 }
404 break;
405 }
406 case AuthenticationType.Basic:
407 {
409 {
410 if (System.Net.NetEventSource.Log.IsEnabled())
411 {
412 System.Net.NetEventSource.AuthenticationError(authUri, "Pre-authentication with " + (isProxyAuth ? "proxy" : "server") + " failed.");
413 }
414 break;
415 }
416 response.Dispose();
419 if (!preAuthenticate)
420 {
421 break;
422 }
423 HttpStatusCode statusCode = response.StatusCode;
424 if (statusCode == HttpStatusCode.Unauthorized || statusCode == HttpStatusCode.ProxyAuthenticationRequired)
425 {
426 if (System.Net.NetEventSource.Log.IsEnabled())
427 {
428 System.Net.NetEventSource.AuthenticationError(authUri, "Pre-authentication with " + (isProxyAuth ? "proxy" : "server") + " failed.");
429 }
430 break;
431 }
432 lock (pool.PreAuthCredentials)
433 {
434 try
435 {
436 if (System.Net.NetEventSource.Log.IsEnabled())
437 {
438 System.Net.NetEventSource.Info(pool.PreAuthCredentials, $"Adding Basic credential to cache, uri={authUri}, username={challenge.Credential.UserName}", "SendWithAuthAsync");
439 }
440 pool.PreAuthCredentials.Add(authUri, "Basic", challenge.Credential);
441 }
442 catch (ArgumentException)
443 {
444 if (System.Net.NetEventSource.Log.IsEnabled())
445 {
446 System.Net.NetEventSource.Info(pool.PreAuthCredentials, $"Basic credential present in cache, uri={authUri}, username={challenge.Credential.UserName}", "SendWithAuthAsync");
447 }
448 }
449 }
450 break;
451 }
452 }
453 }
454 if (System.Net.NetEventSource.Log.IsEnabled() && response.StatusCode == HttpStatusCode.Unauthorized)
455 {
456 System.Net.NetEventSource.AuthenticationError(authUri, (isProxyAuth ? "Proxy" : "Server") + " authentication failed.");
457 }
458 return response;
459 }
void Add(TKey key, TValue value)
static void SetBasicAuthToken(HttpRequestMessage request, NetworkCredential credential, bool isProxyAuth)
static ValueTask< HttpResponseMessage > InnerSendAsync(HttpRequestMessage request, bool async, bool isProxyAuth, bool doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)
static bool IsServerNonceStale(DigestResponse digestResponse)
static bool TryGetAuthenticationChallenge(HttpResponseMessage response, bool isProxyAuth, Uri authUri, ICredentials credentials, out AuthenticationChallenge challenge)
static bool TryGetRepeatedChallenge(HttpResponseMessage response, string scheme, bool isProxyAuth, out string challengeData)
static async ValueTask< bool > TrySetDigestAuthToken(HttpRequestMessage request, NetworkCredential credential, DigestResponse digestResponse, bool isProxyAuth)
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void AuthenticationError(Uri uri, string message)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.Net.NetEventSource.AuthenticationError(), System.cancellationToken, System.Net.NetEventSource.Info(), System.Net.Http.AuthenticationHelper.InnerSendAsync(), System.Net.Http.AuthenticationHelper.IsServerNonceStale(), System.Net.NetEventSource.Log, System.Net.Http.AuthenticationHelper.SetBasicAuthToken(), System.Net.Http.AuthenticationHelper.TryGetAuthenticationChallenge(), System.Net.Http.AuthenticationHelper.TryGetRepeatedChallenge(), and System.Net.Http.AuthenticationHelper.TrySetDigestAuthToken().

Referenced by System.Net.Http.AuthenticationHelper.SendWithProxyAuthAsync(), and System.Net.Http.AuthenticationHelper.SendWithRequestAuthAsync().