Skip to content

Instantly share code, notes, and snippets.

@carloswm85
Last active January 8, 2025 15:34
Show Gist options
  • Save carloswm85/7fc176a4ac6a9c3f9233e8f27d34164a to your computer and use it in GitHub Desktop.
Save carloswm85/7fc176a4ac6a9c3f9233e8f27d34164a to your computer and use it in GitHub Desktop.

An unhandled exception occurred while processing the request.

AuthenticationException: Cannot determine the frame size or a corrupted frame was received.

System.Net.Security.SslStream.GetFrameSize(ReadOnlySpan buffer)

HttpRequestException: The SSL connection could not be established, see inner exception.

System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, bool async, Stream stream, CancellationToken cancellationToken)

AuthenticationFailureException: An error was encountered while handling the remote login.

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()

  • Stack

  • Query

  • Cookies

  • Headers

  • Routing

  • AuthenticationException: Cannot determine the frame size or a corrupted frame was received.

    • System.Net.Security.SslStream.GetFrameSize(ReadOnlySpan buffer)

    • System.Net.Security.SslStream.EnsureFullTlsFrameAsync(CancellationToken cancellationToken, int estimatedSize)

    • System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder+StateMachineBox.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(short token)

    • System.Net.Security.SslStream.ReceiveHandshakeFrameAsync(CancellationToken cancellationToken)

    • System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable+ConfiguredValueTaskAwaiter.GetResult()

    • System.Net.Security.SslStream.ForceAuthenticationAsync(bool receiveFirst, byte[] reAuthenticationData, CancellationToken cancellationToken)

    • System.Net.Security.SslStream.ProcessAuthenticationWithTelemetryAsync(bool isAsync, CancellationToken cancellationToken)

    • System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, bool async, Stream stream, CancellationToken cancellationToken)

  • Show raw exception details

    System.Security.Authentication.AuthenticationException: Cannot determine the frame size or a corrupted frame was received. at System.Net.Security.SslStream.GetFrameSize(ReadOnlySpan`1 buffer) at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken cancellationToken, Int32 estimatedSize) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Security.SslStream.ReceiveHandshakeFrameAsync[TIOAdapter](CancellationToken cancellationToken) at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken) at System.Net.Security.SslStream.ProcessAuthenticationWithTelemetryAsync(Boolean isAsync, CancellationToken cancellationToken) at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)

  • HttpRequestException: The SSL connection could not be established, see inner exception.

    • System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, bool async, Stream stream, CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)

    • System.Threading.Tasks.TaskCompletionSourceWithCancellation.WaitWithCancellationAsync(CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool+HttpConnectionWaiter.WaitForConnectionWithTelemetryAsync(HttpRequestMessage request, HttpConnectionPool pool, bool async, CancellationToken requestCancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool.EstablishProxyTunnelAsync(bool async, CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)

    • System.Threading.Tasks.TaskCompletionSourceWithCancellation.WaitWithCancellationAsync(CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool+HttpConnectionWaiter.WaitForConnectionWithTelemetryAsync(HttpRequestMessage request, HttpConnectionPool pool, bool async, CancellationToken requestCancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)

    • System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, bool async, CancellationToken cancellationToken)

    • System.Threading.Tasks.ValueTask.get_Result()

    • System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)

    • System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, bool disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)

    • Microsoft.AspNetCore.Authentication.OAuth.OAuthHandler.ExchangeCodeAsync(OAuthCodeExchangeContext context)

    • Microsoft.AspNetCore.Authentication.OAuth.OAuthHandler.HandleRemoteAuthenticateAsync()

    • Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()

  • Show raw exception details

    System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: Cannot determine the frame size or a corrupted frame was received. at System.Net.Security.SslStream.GetFrameSize(ReadOnlySpan`1 buffer) at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken cancellationToken, Int32 estimatedSize) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Security.SslStream.ReceiveHandshakeFrameAsync[TIOAdapter](CancellationToken cancellationToken) at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken) at System.Net.Security.SslStream.ProcessAuthenticationWithTelemetryAsync(Boolean isAsync, CancellationToken cancellationToken) at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem) at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.HttpConnectionWaiter`1.WaitForConnectionWithTelemetryAsync(HttpRequestMessage request, HttpConnectionPool pool, Boolean async, CancellationToken requestCancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.EstablishProxyTunnelAsync(Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem) at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.HttpConnectionWaiter`1.WaitForConnectionWithTelemetryAsync(HttpRequestMessage request, HttpConnectionPool pool, Boolean async, CancellationToken requestCancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Microsoft.AspNetCore.Authentication.OAuth.OAuthHandler`1.ExchangeCodeAsync(OAuthCodeExchangeContext context) at Microsoft.AspNetCore.Authentication.OAuth.OAuthHandler`1.HandleRemoteAuthenticateAsync() at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync()

  • AuthenticationFailureException: An error was encountered while handling the remote login.

    • Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()

    • Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

    • Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

  • Show raw exception details

    Microsoft.AspNetCore.Authentication.AuthenticationFailureException: An error was encountered while handling the remote login. ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: Cannot determine the frame size or a corrupted frame was received. at System.Net.Security.SslStream.GetFrameSize(ReadOnlySpan`1 buffer) at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken cancellationToken, Int32 estimatedSize) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Security.SslStream.ReceiveHandshakeFrameAsync[TIOAdapter](CancellationToken cancellationToken) at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken) at System.Net.Security.SslStream.ProcessAuthenticationWithTelemetryAsync(Boolean isAsync, CancellationToken cancellationToken) at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem) at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.HttpConnectionWaiter`1.WaitForConnectionWithTelemetryAsync(HttpRequestMessage request, HttpConnectionPool pool, Boolean async, CancellationToken requestCancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.EstablishProxyTunnelAsync(Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem) at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.HttpConnectionWaiter`1.WaitForConnectionWithTelemetryAsync(HttpRequestMessage request, HttpConnectionPool pool, Boolean async, CancellationToken requestCancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Microsoft.AspNetCore.Authentication.OAuth.OAuthHandler`1.ExchangeCodeAsync(OAuthCodeExchangeContext context) at Microsoft.AspNetCore.Authentication.OAuth.OAuthHandler`1.HandleRemoteAuthenticateAsync() at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync() --- End of inner exception stack trace --- at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync() at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Variable

Value

authuser

0

code

4/0AanRRruyGG5aKxikCWY9yPc9eyd-XOsyfaG-CiYE5N-yE5yb-H4p8gfIGQLIeoALTCeRKg

prompt

consent

scope

email profile openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email

state

CfDJ8LOTzzRPDfFMnAsyLAwWt9j5LTK920cmojSVyh7WJeLRkbJetGmDWBCGyhuofWYtS9jWXPuRlJ0aonFVhfxpoWclnSArANbCxvueAlIBEZgBUunfYM9edd7vXHZYmgykeY1aaGIFp6kw9kqsZADSsOMHn2Z4TpMDAKyOUITsuc0jYTHSCI14itiP51YUapuvG-8WVx2SGANiwi7T3G7mwDdsm4wfjQn-Je_a6Ql1XOWjf9a-lF7jaypLuaEbs_-qzc-e5RMVpTKFiNYLv4NpOqxYAbp_Ubl66JaaCwdIG1TksQ3j6z9ZGEz338az_RxgVDKAHl9k0h-bicxx30EWXG0lL5kPdChYJPyqwFfq6gC2

Variable

Value

.AspNetCore.Correlation.38D6rnKevplIko5RSXrJudl32D0w0YGj1pqzOmKlc8k

N

Variable

Value

Accept

text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7

Accept-Encoding

gzip, deflate, br, zstd

Accept-Language

en

Cache-Control

max-age=0

Connection

close

Cookie

.AspNetCore.Correlation.38D6rnKevplIko5RSXrJudl32D0w0YGj1pqzOmKlc8k=N

dnt

1

Host

localhost:44331

priority

u=0, i

Referer

https://accounts.google.com/

sec-ch-ua

"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"

sec-ch-ua-mobile

?0

sec-ch-ua-platform

"Windows"

sec-fetch-dest

document

sec-fetch-mode

navigate

sec-fetch-site

cross-site

sec-fetch-user

?1

upgrade-insecure-requests

1

User-Agent

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36

x-browser-channel

dev

x-browser-copyright

Copyright 2024 Google LLC. All rights reserved.

x-browser-validation

1nAW9Rb/M8Lkk97ILDg00FWYjns=

x-browser-year

2024

Endpoint

No endpoint.

Route Values

No route values.

/// <summary>
/// Initiates the external login process by redirecting the user to the specified external provider's login page.
/// Every call handles one single provider at the time.
/// </summary>
/// <param name="provider">The name of the external authentication provider (e.g., Google, Facebook).</param>
/// <param name="returnUrl">The URL to which the user should be redirected after a successful login.</param>
/// <returns>
/// A ChallengeResult that triggers the external authentication process with the specified provider.
/// Notice the resulting callback is set in it ("ExternalLoginCallback").
/// </returns>
[AllowAnonymous]
[HttpPost]
public IActionResult ExternalLogin(string provider, string? returnUrl)
{
// Build the URL for the external login callback, including the return URL parameter
var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl })
?? throw new InvalidOperationException("Callback URL generation failed.");
// Configure the properties for the external authentication process, including the redirect URL
var properties = signInManager?.ConfigureExternalAuthenticationProperties(provider, redirectUrl)
?? throw new NullReferenceException("SignInManager is not initialized.");
// Return a ChallengeResult to trigger the external login with the specified provider
return new ChallengeResult(provider, properties);
}
/// <summary>
/// Handles the callback after an external login attempt.
/// </summary>
/// <param name="returnUrl">The URL to return to after a successful login.</param>
/// <param name="remoteError">An error message returned by the external login provider, if any.</param>
/// <returns>An IActionResult that redirects the user or shows an error page.</returns>
[AllowAnonymous]
public async Task<IActionResult>
ExternalLoginCallback(string? returnUrl = null, string? remoteError = null)
{
// If returnUrl is null, default to the home page
returnUrl = returnUrl ?? Url.Content("~/");
// Prepare the LoginViewModel with the return URL and external login schemes
LoginViewModel loginViewModel = new LoginViewModel
{
ReturnUrl = returnUrl,
ExternalLogins =
(await signInManager.GetExternalAuthenticationSchemesAsync()).ToList()
};
// ERROR #1: Handle any errors from the external login provider
if (remoteError != null)
{
// Add an error to the model state to be displayed on the login page
ModelState
.AddModelError(string.Empty, $"Error from external provider: {remoteError}");
// Return the login view with the error message
return View("Login", loginViewModel);
}
// Get the login information about the user from the external login provider
// User claims from the provider are contained here
var info = await signInManager.GetExternalLoginInfoAsync();
// ERROR #2: Handle cases where external login information is not available
if (info == null)
{
// Add an error to the model state and return the login view
ModelState
.AddModelError(string.Empty, "Error loading external login information.");
return View("Login", loginViewModel);
}
// Check if the user already has a login associated with this external provider
var signInResult = await signInManager.ExternalLoginSignInAsync(info.LoginProvider,
info.ProviderKey, isPersistent: false, bypassTwoFactor: true);
// `isPersistent` determines whether the session is maintained across browser restarts
// `bypassTwoFactor` allows bypassing two-factor authentication during this login attempt
if (signInResult.Succeeded)
{
// Redirect the user to the specified return URL upon successful sign-in
return LocalRedirect(returnUrl);
}
else
{
// Handle the case where the user does not have a local account
// Get the user's email from the external login claims
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
if (email != null)
{
// Check if a user with this email already exists
var user = await userManager.FindByEmailAsync(email);
// If the user does not exist, create a new one without a password
if (user == null)
{
user = new ApplicationUser
{
UserName = info.Principal.FindFirstValue(ClaimTypes.Email),
Email = info.Principal.FindFirstValue(ClaimTypes.Email)
};
// Create the new user in the database
await userManager.CreateAsync(user);
}
// Link the external login to the newly created or existing user
await userManager.AddLoginAsync(user, info);
// Sign in the user with the new login credentials
await signInManager.SignInAsync(user, isPersistent: false);
// Redirect the user to the specified return URL
return LocalRedirect(returnUrl);
}
// If no email claim is received, display an error page
ViewBag.ErrorTitle = $"Email claim not received from: {info.LoginProvider}";
ViewBag.ErrorMessage = "Please contact support on [email protected]";
return View("Error");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment