Skip to content

Commit a8f7750

Browse files
committed
Microsoft.AspnetCore.Authentication.Google -> Google.Apis.Auth.AspNetCore3
1 parent e14ded1 commit a8f7750

File tree

2 files changed

+65
-55
lines changed

2 files changed

+65
-55
lines changed

src/content/docs/identityserver/quickstarts/2-interactive.md

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ To enable OIDC in IdentityServer you need:
4545
### Add The UI
4646

4747
Support for the OpenID Connect protocol is already built into IdentityServer.
48-
You need to provide the User Interface for login, logout, consent and error.
48+
You need to provide the User Interface for login, logout, consent, and error.
4949

5050
While the look & feel and workflows will differ in each implementation, we
5151
provide a Razor Pages-based UI that you can use as a starting point. You can use
@@ -542,82 +542,90 @@ Adding support for external authentication to your IdentityServer can be done
542542
with very little code; all that is needed is an authentication handler.
543543

544544
ASP.NET Core ships with handlers for Google, Facebook, Twitter, Microsoft
545-
Account and OpenID Connect. In addition, you can find handlers for many
545+
Account, and OpenID Connect. In addition, you can find handlers for many
546546
other authentication providers
547547
[here](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers).
548548
549549
#### Add Google support
550550

551+
:::note[`Microsoft.AspnetCore.Authentication.Google` no longer maintained]
552+
Before .NET 10, a package `Microsoft.AspnetCore.Authentication.Google` was provided by Microsoft. Starting with .NET 10,
553+
Microsoft [stopped shipping new versions of the `Microsoft.AspnetCore.Authentication.Google` package](https://github.com/dotnet/aspnetcore/issues/61817).
554+
555+
Starting with .NET 5, Google started shipping the [`Google.Apis.Auth.AspNetCore3`](https://www.nuget.org/packages/Google.Apis.Auth.AspNetCore3/)
556+
package. We recommend using this package going forward.
557+
:::
558+
551559
To use Google for authentication, you need to:
552560

553-
- Add the `Microsoft.AspNetCore.Authentication.Google` NuGet package to
554-
the IdentityServer project.
555-
- Register with Google and set up a client.
556-
- Store the client id and secret securely with *dotnet user-secrets*.
557-
- Add the Google authentication handler to the middleware pipeline and configure
558-
it.
561+
- Add the `Google.Apis.Auth.AspNetCore3` NuGet package to the IdentityServer project.
562+
- Register with Google and [set up a client](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-9.0#create-the-google-oauth-20-client-id-and-secret).
563+
- Store the client id and secret securely with `dotnet user-secrets`.
564+
- Add the Google authentication handler to the middleware pipeline and configure it.
559565

560-
See [Microsoft's
561-
guide](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-8.0#create-a-google-api-console-project-and-client-id)
566+
See [Microsoft's guide](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-9.0#create-the-google-oauth-20-client-id-and-secret)
562567
for details on how to register with Google, create the client, and store the
563-
secrets in user-secrets. **Stop before adding the authentication middleware and
568+
secrets in user secrets. **Stop before adding the authentication middleware and
564569
Google authentication handler to the pipeline.** You will need an
565570
IdentityServer specific option.
566571

567-
Add the following to `ConfigureServices` in
568-
`src/IdentityServer/HostingExtensions.cs`:
572+
Add the following to `ConfigureServices` in `src/IdentityServer/HostingExtensions.cs`:
569573

570574
```cs
571575
// Program.cs
572576
builder.Services.AddAuthentication()
573-
.AddGoogle("Google", options =>
574-
{
575-
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
576-
577-
options.ClientId = builder.Configuration["Authentication:Google:ClientId"];
578-
options.ClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
579-
});
577+
.AddGoogleOpenIdConnect(
578+
authenticationScheme: GoogleOpenIdConnectDefaults.AuthenticationScheme,
579+
displayName: "Google",
580+
configureOptions: options =>
581+
{
582+
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
583+
584+
options.ClientId = builder.Configuration["Authentication:Google:ClientId"];
585+
options.ClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
586+
587+
options.CallbackPath = "/signin-google";
588+
});
580589
```
581590

582-
When authenticating with Google, there are again two [authentication
583-
schemes](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/?view=aspnetcore-8.0#authentication-scheme).
584-
`AddGoogle` adds the Google scheme, which handles the protocol flow back and
585-
forth with Google. After successful login, the application needs to sign in to
586-
an additional scheme that can authenticate future requests without needing a
587-
roundtrip to Google - typically by issuing a local cookie. The `SignInScheme`
588-
tells the Google handler to use the scheme named
589-
`IdentityServerConstants.ExternalCookieAuthenticationScheme`, which is a cookie
590-
authentication handler automatically created by IdentityServer that is intended
591-
for external logins.
591+
:::note
592+
Note that the `authenticationScheme` and `displayName` parameters are optional. They are added here to make the login
593+
button display a short and concise "Google" instad of the default "Google OpenIdConnect".
594+
:::
595+
596+
When authenticating with Google, there are again two [authentication schemes](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/#authentication-scheme).
597+
`AddGoogleOpenIdConnect` adds the `GoogleOpenIdConnect` scheme, which handles the protocol flow back and forth with Google.
598+
After successful login, the application needs to sign in to an additional scheme that can authenticate future requests without
599+
needing a roundtrip to Google - typically by issuing a local cookie. The `SignInScheme` tells the Google handler to use
600+
the scheme named `IdentityServerConstants.ExternalCookieAuthenticationScheme`, which is a cookie authentication handler
601+
automatically created by IdentityServer that is intended for external logins.
592602

593-
Now run `IdentityServer` and `WebClient` and try to authenticate (you may need
594-
to log out and log back in). You will see a Google button on the login page.
603+
Now run `IdentityServer` and `WebClient` and try to authenticate (you may need to log out and log back in)
604+
You will see a *Google* button on the login page.
595605

596606
![IdentityServer login page showing Google as an external login option](./images/2_google_login.png)
597607

598-
Click on Google and authenticate with a Google account. You should land back on
608+
Click on *Google* and authenticate with a Google account. You should land back on
599609
the `WebClient` home page, showing that the user is now coming from Google with
600610
claims sourced from Google's data.
601611

602612
:::note
603-
The Google button is rendered by the login page automatically when there are
604-
external providers registered as authentication schemes. See the
605-
`BuildModelAsync` method in `src/IdentityServer/Pages/Account/Login/Index.cshtml.cs` and
613+
The Google button is rendered by the login page automatically when there are external providers registered as
614+
authentication schemes. See the `BuildModelAsync` method in `src/IdentityServer/Pages/Account/Login/Index.cshtml.cs` and
606615
the corresponding Razor template for more details.
607616
:::
608617

609-
#### Adding an additional OpenID Connect-based external provider
618+
#### Adding An Additional OpenID Connect-Based External Provider
610619

611620
A [cloud-hosted demo](https://demo.duendesoftware.com) version of Duende
612621
IdentityServer can be added as an additional external provider.
613622

614-
Register and configure the services for the OpenId Connect handler in
615-
`src/IdentityServer/HostingExtensions.cs`:
623+
Register and configure the services for the OpenId Connect handler in`src/IdentityServer/HostingExtensions.cs`:
616624

617625
```cs
618626
// HostingExtensions.cs
619627
builder.Services.AddAuthentication()
620-
.AddGoogle("Google", options => { /* ... */ })
628+
.AddGoogleOpenIdConnect(/* ... */)
621629
.AddOpenIdConnect("oidc", "Demo IdentityServer", options =>
622630
{
623631
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

src/content/docs/identityserver/ui/login/external.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,20 @@ authentication and configuring it.
329329

330330
In this section, find a non-exhaustive list of first-party and third-party ASP.NET authentication handlers that you can use in any ASP.NET Core application.
331331

332-
| Authentication handler / Service | Type |
333-
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
334-
| [Cookie authentication](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie) | Part of .NET |
335-
| [OpenID Connect](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/configure-oidc-web-authentication) | Part of .NET |
336-
| [JWT Bearer authentication](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/configure-jwt-bearer-authentication) | Part of .NET |
337-
| [Certificate authentication](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/certauth) | Part of .NET |
338-
| [Windows authentication](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth) | Part of .NET |
339-
| [WS-Federation](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/ws-federation) | Part of .NET |
340-
| [Facebook / Meta](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/facebook-logins) | Part of .NET |
341-
| [Microsoft Account](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/microsoft-logins) | Part of .NET |
342-
| [Twitter / X](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/twitter-logins) | Part of .NET |
343-
| [Sustainsys Saml2](https://sustainsys.com/sustainsyssaml2-libraries) | Open-source |
344-
| Many social providers in [AspNet.Security.OAuth.Providers](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers)<br /><em><small>Airtable, Apple ID, GitHub, Hubspot, Instagram, Okta, Slack, ...</small></em> | Open-source |
345-
| [Rock Solid Knowledge SAML2P](https://www.identityserver.com/products/saml2p) | Commercial |
346-
| [Rock Solid Knowledge WS-Federation](https://www.identityserver.com/products/ws-federation) | Commercial |
332+
| Authentication handler / Service | Vendor |
333+
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
334+
| [Cookie authentication](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie) | Part of .NET |
335+
| [OpenID Connect](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/configure-oidc-web-authentication) | Part of .NET |
336+
| [JWT Bearer authentication](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/configure-jwt-bearer-authentication) | Part of .NET |
337+
| [Certificate authentication](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/certauth) | Part of .NET |
338+
| [Windows authentication](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth) | Part of .NET |
339+
| [WS-Federation](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/ws-federation) | Part of .NET |
340+
| [Facebook / Meta](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/facebook-logins) | Part of .NET |
341+
| [Microsoft Account](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/microsoft-logins) | Part of .NET |
342+
| [Twitter / X](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/twitter-logins) | Part of .NET |
343+
| [Entra ID / Microsoft Account / ...](https://www.nuget.org/packages/Microsoft.Identity.Web) | Microsoft |
344+
| [Google](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins) | Google |
345+
| [Sustainsys Saml2](https://sustainsys.com/sustainsyssaml2-libraries) | Open-source |
346+
| Many social providers in [AspNet.Security.OAuth.Providers](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers)<br /><em><small>Airtable, Apple ID, GitHub, Hubspot, Instagram, Okta, Slack, ...</small></em> | Open-source |
347+
| [Rock Solid Knowledge SAML2P](https://www.identityserver.com/products/saml2p) | Rock Solid Knowledge |
348+
| [Rock Solid Knowledge WS-Federation](https://www.identityserver.com/products/ws-federation) | Rock Solid Knowledge |

0 commit comments

Comments
 (0)