Skip to content

Commit 2f998c4

Browse files
committed
Demonstrate AddOpenIdConnect with demo.duendesoftware.com as the first step in documentation.
1 parent 12733cc commit 2f998c4

File tree

1 file changed

+55
-65
lines changed

1 file changed

+55
-65
lines changed

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

Lines changed: 55 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -541,19 +541,64 @@ will automatically include requested claims from the test users added in
541541
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

544-
ASP.NET Core ships with handlers for Google, Facebook, Twitter, Microsoft
545-
Account, and OpenID Connect. In addition, you can find handlers for many
546-
other authentication providers
547-
[here](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers).
544+
ASP.NET Core ships with handlers for OpenID Connect, and provides [integrations for Google, Facebook, Microsoft Account, Entra ID, and more](/identityserver/ui/login/external.md#third-party-aspnet-core-authentication-handlers).
548545

549-
#### Add Google support
546+
In this section, you'll register the Duende IdentityServer demo instance at `demo.duendesoftware.com` as an external provider.
547+
Since no other configuration is required apart from your IdentityServer, it is a good starting point.
548+
You'll also see [how to add Google authentication support](#add-google-support).
549+
550+
#### Adding An Additional OpenID Connect-Based External Provider
551+
552+
A cloud-hosted [demo instance of Duende IdentityServer](https://demo.duendesoftware.com) can be added as an additional external provider.
553+
554+
Register and configure the services for the OpenId Connect handler in`src/IdentityServer/HostingExtensions.cs`:
555+
556+
```cs
557+
// HostingExtensions.cs
558+
builder.Services.AddAuthentication()
559+
.AddOpenIdConnect("oidc", "Sign-in with demo.duendesoftware.com", options =>
560+
{
561+
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
562+
options.SignOutScheme = IdentityServerConstants.SignoutScheme;
563+
options.SaveTokens = true;
564+
565+
options.Authority = "https://demo.duendesoftware.com";
566+
options.ClientId = "interactive.confidential";
567+
options.ClientSecret = "secret";
568+
options.ResponseType = "code";
569+
570+
options.TokenValidationParameters = new TokenValidationParameters
571+
{
572+
NameClaimType = "name",
573+
RoleClaimType = "role"
574+
};
575+
});
576+
```
577+
578+
Now if you try to authenticate, you should see an additional *Sign-in with demo.duendesoftware.com* button to log in to
579+
the cloud-hosted demo IdentityServer. If you click that button, you will be redirected to https://demo.duendesoftware.com/.
580+
581+
Check that the page's location has changed and then log in using the `alice` or `bob` users (their passwords are their usernames, just as
582+
they are for the local test users). You should land back at `WebClient`, authenticated with a demo user.
583+
584+
The demo users are logically distinct entities from the local test users, even though they happen to have identical usernames.
585+
Inspect their claims in `WebClient` and note the differences between them, such as the distinct `sub` claims.
586+
587+
:::note
588+
The quickstart UI auto-provisions external users. When an external user logs in for the first time, a new local user is
589+
created with a copy of all the external user's claims. This auto-provisioning process occurs in the `OnGet` method of
590+
`src/IdentityServer/Pages/ExternalLogin/Callback.cshtml.cs`, and is completely customizable.
591+
For example, you could modify `Callback` so that it will require registration before provisioning the external user.
592+
:::
593+
594+
#### Add Google Support
550595

551596
:::note[`Microsoft.AspnetCore.Authentication.Google` no longer maintained]
552597
Before .NET 10, the `Microsoft.AspnetCore.Authentication.Google` package was provided by Microsoft. Starting with .NET 10,
553598
Microsoft [stopped shipping new versions of the `Microsoft.AspnetCore.Authentication.Google` package](https://github.com/dotnet/aspnetcore/issues/61817).
554599
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.
600+
To add Google authentication, we recommend using the [`Google.Apis.Auth.AspNetCore3`](https://www.nuget.org/packages/Google.Apis.Auth.AspNetCore3/)
601+
package that is shipped by Google.
557602
:::
558603

559604
To use Google for authentication, you need to:
@@ -581,10 +626,8 @@ builder.Services.AddAuthentication()
581626
{
582627
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
583628

584-
options.ClientId = builder.Configuration["Authentication:Google:ClientId"];
585-
options.ClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
586-
587-
options.CallbackPath = "/signin-google";
629+
options.ClientId = "" builder.Configuration["Authentication:Google:ClientId"];
630+
options.ClientSecret = ""builder.Configuration["Authentication:Google:ClientSecret"];
588631
});
589632
```
590633

@@ -613,57 +656,4 @@ claims sourced from Google's data.
613656
The Google button is rendered by the login page automatically when there are external providers registered as
614657
authentication schemes. See the `BuildModelAsync` method in `src/IdentityServer/Pages/Account/Login/Index.cshtml.cs` and
615658
the corresponding Razor template for more details.
616-
:::
617-
618-
#### Adding An Additional OpenID Connect-Based External Provider
619-
620-
A [cloud-hosted demo](https://demo.duendesoftware.com) version of Duende
621-
IdentityServer can be added as an additional external provider.
622-
623-
Register and configure the services for the OpenId Connect handler in`src/IdentityServer/HostingExtensions.cs`:
624-
625-
```cs
626-
// HostingExtensions.cs
627-
builder.Services.AddAuthentication()
628-
.AddGoogleOpenIdConnect(/* ... */)
629-
.AddOpenIdConnect("oidc", "Demo IdentityServer", options =>
630-
{
631-
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
632-
options.SignOutScheme = IdentityServerConstants.SignoutScheme;
633-
options.SaveTokens = true;
634-
635-
options.Authority = "https://demo.duendesoftware.com";
636-
options.ClientId = "interactive.confidential";
637-
options.ClientSecret = "secret";
638-
options.ResponseType = "code";
639-
640-
options.TokenValidationParameters = new TokenValidationParameters
641-
{
642-
NameClaimType = "name",
643-
RoleClaimType = "role"
644-
};
645-
});
646-
```
647-
648-
Now if you try to authenticate, you should see an additional button to log in to
649-
the cloud-hosted Demo IdentityServer. If you click that button, you will be
650-
redirected to https://demo.duendesoftware.com/. Note that the demo site is using
651-
the same UI as your site, so there will not be very much that changes visually
652-
when you're redirected. Check that the page's location has changed and then log
653-
in using the alice or bob users (their passwords are their usernames, just as
654-
they are for the local test users). You should land back at `WebClient`,
655-
authenticated with a demo user.
656-
657-
The demo users are logically distinct entities from the local test
658-
users, even though they happen to have identical usernames. Inspect their claims
659-
in `WebClient` and note the differences between them, such as the distinct sub
660-
claims.
661-
662-
:::note
663-
The quickstart UI auto-provisions external users. When an external user logs in
664-
for the first time, a new local user is created with a copy of all the external
665-
user's claims. This auto-provisioning process occurs in the `OnGet` method of
666-
`src/IdentityServer/Pages/ExternalLogin/Callback.cshtml.cs`, and is completely
667-
customizable. For example, you could modify `Callback` so that it will require
668-
registration before provisioning the external user.
669-
:::
659+
:::

0 commit comments

Comments
 (0)