Skip to content

Commit 1cb6171

Browse files
authored
Merge pull request #36975 from dotnet/main
2 parents 3deba42 + 622c946 commit 1cb6171

File tree

12 files changed

+39
-27
lines changed

12 files changed

+39
-27
lines changed

aspnetcore/security/authentication/social/additional-claims.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Specify the list of permissions to retrieve from the provider by specifying the
4646
| Microsoft | `https://login.microsoftonline.com/common/oauth2/v2.0/authorize` |
4747
| Twitter | `https://api.twitter.com/oauth/authenticate` |
4848

49-
In the sample app, Google's `profile`, `email`, and `openid` scopes are automatically added by the framework when <xref:Microsoft.Extensions.DependencyInjection.GoogleExtensions.AddGoogle%2A> is called on the <xref:Microsoft.AspNetCore.Authentication.AuthenticationBuilder>. If the app requires additional scopes, add them to the options. In the following example, the Google `https://www.googleapis.com/auth/user.birthday.read` scope is added to retrieve a user's birthday:
49+
In the sample app, Google's `profile`, `email`, and `openid` scopes are automatically added by the framework when `Microsoft.Extensions.DependencyInjection.GoogleOpenIdConnectExtensions.AddGoogleOpenIdConnect` is called on the <xref:Microsoft.AspNetCore.Authentication.AuthenticationBuilder>. If the app requires additional scopes, add them to the options. In the following example, the Google `https://www.googleapis.com/auth/user.birthday.read` scope is added to retrieve a user's birthday:
5050

5151
```csharp
5252
options.Scope.Add("https://www.googleapis.com/auth/user.birthday.read");
@@ -80,7 +80,7 @@ If a large amount of user data is required for processing user requests:
8080

8181
<xref:Microsoft.AspNetCore.Authentication.RemoteAuthenticationOptions.SaveTokens*> defines whether access and refresh tokens should be stored in the <xref:Microsoft.AspNetCore.Http.Authentication.AuthenticationProperties> after a successful authorization. `SaveTokens` is set to `false` by default to reduce the size of the final authentication cookie.
8282

83-
The sample app sets the value of `SaveTokens` to `true` in <xref:Microsoft.AspNetCore.Authentication.Google.GoogleOptions>:
83+
The sample app sets the value of `SaveTokens` to `true` in <xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions>:
8484

8585
[!code-csharp[](additional-claims/samples/6.x/ClaimsSample/Program.cs?name=snippet_AddGoogle2&highlight=9)]
8686

aspnetcore/security/authentication/social/additional-claims/samples/6.x/ClaimsSample/Program.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
var configuration = builder.Configuration;
99

1010
#region snippet_AddGoogle2
11-
builder.Services.AddAuthentication().AddGoogle(googleOptions =>
11+
builder.Services.AddAuthentication().AddGoogleOpenIdConnect(googleOptions =>
1212
{
1313
googleOptions.ClientId = configuration["Authentication:Google:ClientId"];
1414
googleOptions.ClientSecret = configuration["Authentication:Google:ClientSecret"];
@@ -18,17 +18,20 @@
1818

1919
googleOptions.SaveTokens = true;
2020

21-
googleOptions.Events.OnCreatingTicket = ctx =>
21+
googleOptions.Events.OnTicketReceived = ctx =>
2222
{
23-
List<AuthenticationToken> tokens = ctx.Properties.GetTokens().ToList();
23+
List<AuthenticationToken>? tokens = ctx.Properties?.GetTokens().ToList();
2424

25-
tokens.Add(new AuthenticationToken()
25+
tokens?.Add(new AuthenticationToken()
2626
{
2727
Name = "TicketCreated",
2828
Value = DateTime.UtcNow.ToString()
2929
});
3030

31-
ctx.Properties.StoreTokens(tokens);
31+
if (tokens is not null)
32+
{
33+
ctx.Properties?.StoreTokens(tokens);
34+
}
3235

3336
return Task.CompletedTask;
3437
};

aspnetcore/security/authentication/social/additional-claims/samples/6.x/ClaimsSample/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ The sample app demonstrates how to:
88
To use the sample app:
99

1010
1. Register the app and obtain a valid client ID and client secret for Google authentication. For more information, see [Google external login setup](https://learn.microsoft.com/aspnet/core/security/authentication/social/google-logins).
11-
1. Provide the client ID and client secret to the app in the [GoogleOptions](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.authentication.google.googleoptions) of `Startup.ConfigureServices`.
11+
1. Provide the client ID and client secret to the app using the Secret Manager.
1212
1. Run the app and request the My Claims page. When the user isn't signed in, the app redirects to Google. Sign in with Google. Google redirects the user back to the app (`/MyClaims`). The user is authenticated, and the My Claims page is loaded. The given name and surname claims are present under **User Claims** with the values provided by Google. The access token is displayed under **Authentication Properties**.

aspnetcore/security/authentication/social/additional-claims/samples/6.x/ClaimsSample/WebGoogOauth.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.2" />
11+
<PackageReference Include="Google.Apis.Auth.AspNetCore3" Version="1.73.0" />
1212
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.2" />
1313
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.2" />
1414
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.2" />
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="WebGoogOauth.csproj" />
3+
</Solution>

aspnetcore/security/authentication/social/google-logins.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: wadepickett
44
description: This tutorial demonstrates the integration of Google account user authentication into an existing ASP.NET Core app.
55
ms.author: wpickett
66
ms.custom: mvc
7-
ms.date: 12/26/2025
7+
ms.date: 04/09/2026
88
uid: security/authentication/google-logins
99
---
1010
# Google external login setup in ASP.NET Core
@@ -46,7 +46,7 @@ Create the client credentials for the app by opening the **Clients** sidebar men
4646
* Save the **Client ID** and **Client secret**, which are used later in the ASP.NET app configuration.
4747

4848
> [!NOTE]
49-
> The URI segment `/signin-google` is set as the default callback of the Google authentication provider. It's possible to change the default callback URI while configuring the Google authentication middleware via the inherited <xref:Microsoft.AspNetCore.Authentication.RemoteAuthenticationOptions.CallbackPath%2A?displayProperty=nameWithType> property of the <xref:Microsoft.AspNetCore.Authentication.Google.GoogleOptions> class.
49+
> The URI segment `/signin-google` is set as the default callback of the Google authentication provider. It's possible to change the default callback URI while configuring the Google authentication middleware via the inherited <xref:Microsoft.AspNetCore.Authentication.RemoteAuthenticationOptions.CallbackPath%2A?displayProperty=nameWithType> property.
5050
5151
When deploying the app, either:
5252

@@ -71,14 +71,14 @@ Manage API credentials and usage in the [API Console](https://console.developers
7171
7272
## Configure Google authentication
7373
74-
Add the [`Microsoft.AspNetCore.Authentication.Google`](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Google) nuget package:
74+
:::moniker range=">= aspnetcore-6.0"
75+
76+
Add the [`Google.Apis.Auth.AspNetCore3` NuGet package](https://www.nuget.org/packages/Google.Apis.Auth.AspNetCore3) to the app:
7577
7678
```dotnetcli
77-
dotnet add package Microsoft.AspNetCore.Authentication.Google
79+
dotnet add package Google.Apis.Auth.AspNetCore3
7880
```
7981

80-
:::moniker range=">= aspnetcore-6.0"
81-
8282
Add the authentication service to the `Program` file:
8383

8484
:::code language="csharp" source="~/security/authentication/social/social-code/6.x/ProgramGoogle.cs" id="snippet1":::
@@ -87,6 +87,12 @@ Add the authentication service to the `Program` file:
8787

8888
:::moniker range="< aspnetcore-6.0"
8989

90+
Add the [`Microsoft.AspNetCore.Authentication.Google` NuGet package](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Google) to the app:
91+
92+
```dotnetcli
93+
dotnet add package Microsoft.AspNetCore.Authentication.Google
94+
```
95+
9096
Add the authentication service to `Startup.ConfigureServices`:
9197

9298
```csharp

aspnetcore/security/authentication/social/social-code/6.x/ProgramGoogle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var configuration = builder.Configuration;
44

55
// <snippet1>
6-
services.AddAuthentication().AddGoogle(googleOptions =>
6+
services.AddAuthentication().AddGoogleOpenIdConnect(googleOptions =>
77
{
88
googleOptions.ClientId = configuration["Authentication:Google:ClientId"];
99
googleOptions.ClientSecret = configuration["Authentication:Google:ClientSecret"];

aspnetcore/security/authentication/social/social-without-identity.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: serpent5
44
description: Use Facebook, Google, Twitter, etc. account user authentication without ASP.NET Core Identity.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: tdykstra
7-
ms.date: 04/05/2022
7+
ms.date: 04/09/2026
88
uid: security/authentication/social/social-without-identity
99
---
1010
# Use social sign-in provider authentication without ASP.NET Core Identity
@@ -38,7 +38,7 @@ The call to <xref:Microsoft.Extensions.DependencyInjection.AuthenticationService
3838
* <xref:Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.SignInAsync%2A>
3939
* <xref:Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.SignOutAsync%2A>
4040

41-
Setting the app's `DefaultScheme` to <xref:Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationDefaults.AuthenticationScheme?displayProperty=nameWithType> ("Cookies") configures the app to use Cookies as the default scheme for these extension methods. Setting the app's <xref:Microsoft.AspNetCore.Authentication.AuthenticationOptions.DefaultChallengeScheme> to <xref:Microsoft.AspNetCore.Authentication.Google.GoogleDefaults.AuthenticationScheme?displayProperty=nameWithType> ("Google") configures the app to use Google as the default scheme for calls to `ChallengeAsync`. `DefaultChallengeScheme` overrides `DefaultScheme`. See <xref:Microsoft.AspNetCore.Authentication.AuthenticationOptions> for more properties that override `DefaultScheme` when set.
41+
Setting the app's `DefaultScheme` to <xref:Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationDefaults.AuthenticationScheme?displayProperty=nameWithType> ("Cookies") configures the app to use Cookies as the default scheme for these extension methods. Setting the app's <xref:Microsoft.AspNetCore.Authentication.AuthenticationOptions.DefaultChallengeScheme> to `Google.Apis.Auth.AspNetCore3.GoogleOpenIdConnectDefaults.AuthenticationScheme` ("`GoogleOpenIdConnect`") configures the app to use Google as the default scheme for calls to `ChallengeAsync`. `DefaultChallengeScheme` overrides `DefaultScheme`. See <xref:Microsoft.AspNetCore.Authentication.AuthenticationOptions> for more properties that override `DefaultScheme` when set.
4242

4343
In `Program.cs`, call <xref:Microsoft.AspNetCore.Builder.AuthAppBuilderExtensions.UseAuthentication%2A> and <xref:Microsoft.AspNetCore.Builder.AuthorizationAppBuilderExtensions.UseAuthorization%2A>. This middleware combination sets the <xref:Microsoft.AspNetCore.Http.HttpContext.User%2A?displayProperty=nameWithType> property and runs the Authorization Middleware for requests:
4444

aspnetcore/security/authentication/social/social-without-identity/samples/6.x/SocialWithoutIdentitySample/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// <snippet_AddAuthentication>
22
using Microsoft.AspNetCore.Authentication.Cookies;
3-
using Microsoft.AspNetCore.Authentication.Google;
3+
using Google.Apis.Auth.AspNetCore3;
44

55
var builder = WebApplication.CreateBuilder(args);
66

77
builder.Services
88
.AddAuthentication(options =>
99
{
1010
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
11-
options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
11+
options.DefaultChallengeScheme = GoogleOpenIdConnectDefaults.AuthenticationScheme;
1212
})
1313
.AddCookie()
14-
.AddGoogle(options =>
14+
.AddGoogleOpenIdConnect(options =>
1515
{
1616
options.ClientId = builder.Configuration["Authentication:Google:ClientId"];
1717
options.ClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];

aspnetcore/security/authentication/social/social-without-identity/samples/6.x/SocialWithoutIdentitySample/Snippets/Pages/Privacy.cshtml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Microsoft.AspNetCore.Authentication;
2-
using Microsoft.AspNetCore.Authentication.Google;
2+
using Google.Apis.Auth.AspNetCore3;
33
using Microsoft.AspNetCore.Authorization;
44
using Microsoft.AspNetCore.Mvc.RazorPages;
55

@@ -12,7 +12,7 @@ public class PrivacyModel : PageModel
1212
public async Task OnGetAsync()
1313
{
1414
var accessToken = await HttpContext.GetTokenAsync(
15-
GoogleDefaults.AuthenticationScheme, "access_token");
15+
GoogleOpenIdConnectDefaults.AuthenticationScheme, "access_token");
1616

1717
// ...
1818
}

0 commit comments

Comments
 (0)