Back to results for “OAuth”
.NET › Authentication & Authorization (Identity, JWT, OAuth)

How do you integrate external identity providers (Google, Microsoft Entra ID, Facebook) using OAuth/OpenID Connect in ASP.NET Core?

Advanced

Answer

ASP.NET Core provides dedicated authentication handler packages (Microsoft.AspNetCore.Authentication.Google, .MicrosoftAccount, etc., or the generic OpenID Connect handler for any compliant provider) that implement the OAuth/OIDC redirect flow, handle token exchange, and map the provider's returned claims into a local ClaimsPrincipal -- letting users 'Sign in with Google' without the application ever handling their Google password directly.
builder.Services.AddAuthentication()
    .AddGoogle(options => {
        options.ClientId = builder.Configuration["Google:ClientId"];
        options.ClientSecret = builder.Configuration["Google:ClientSecret"];
    });

// Triggering the flow:
// GET /Account/ExternalLogin?provider=Google
Real-world example A B2B SaaS platform lets enterprise customers sign in with Microsoft Entra ID (formerly Azure AD) using the OpenID Connect handler, integrating with each customer's existing corporate identity system instead of maintaining separate app-specific passwords.

Common follow-ups: What's the difference between OAuth 2.0 and OpenID Connect?;How do you link an external login to an existing local account?