Skip to content

Commit 8160ea7

Browse files
authored
Fixed typo in code sample (dotnet#28358)
1 parent 2c0bdd9 commit 8160ea7

File tree

1 file changed

+24
-24
lines changed
  • aspnetcore/blazor/hybrid/security

1 file changed

+24
-24
lines changed

aspnetcore/blazor/hybrid/security/index.md

+24-24
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ zone_pivot_groups: blazor-hybrid-frameworks
1313

1414
This article describes ASP.NET Core's support for the configuration and management of security and ASP.NET Core Identity in Blazor Hybrid apps.
1515

16-
::: moniker range=">= aspnetcore-6.0 < aspnetcore-7.0"
16+
::: moniker range=">= aspnetcore-7.0"
1717

1818
Authentication in Blazor Hybrid apps is handled by native platform libraries, as they offer enhanced security guarantees that the browser sandbox can't offer. Authentication of native apps uses an OS-specific mechanism or via a federated protocol, such as [OpenID Connect (OIDC)](https://openid.net/connect/). Follow the guidance for the identity provider that you've selected for the app and then further integrate identity with Blazor using the guidance in this article.
1919

@@ -121,7 +121,7 @@ Replace the preceding line of code with the following code. Add OpenID/MSAL code
121121

122122
```csharp
123123
builder.Services.AddAuthorizationCore();
124-
builder.Services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
124+
builder.Services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
125125
builder.Services.AddSingleton<AuthenticatedUser>();
126126
var host = builder.Build();
127127

@@ -169,7 +169,7 @@ Replace the preceding line of code with the following code. Add OpenID/MSAL code
169169

170170
```csharp
171171
serviceCollection.AddAuthorizationCore();
172-
serviceCollection.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
172+
serviceCollection.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
173173
serviceCollection.AddSingleton<AuthenticatedUser>();
174174
var services = serviceCollection.BuildServiceProvider();
175175
Resources.Add("services", services);
@@ -215,7 +215,7 @@ Replace the preceding line of code with the following code. Add OpenID/MSAL code
215215

216216
```csharp
217217
services.AddAuthorizationCore();
218-
services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
218+
services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
219219
services.AddSingleton<AuthenticatedUser>();
220220
var serviceCollection = services.BuildServiceProvider();
221221
blazorWebView1.Services = serviceCollection;
@@ -309,7 +309,7 @@ Add the authorization services and Blazor abstractions to the service collection
309309

310310
```csharp
311311
builder.Services.AddAuthorizationCore();
312-
builder.Services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
312+
builder.Services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
313313
builder.Services.AddSingleton<ExternalAuthService>();
314314
```
315315

@@ -327,7 +327,7 @@ Add the authorization services and the Blazor abstractions to the service collec
327327

328328
```csharp
329329
serviceCollection.AddAuthorizationCore();
330-
serviceCollection.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
330+
serviceCollection.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
331331
serviceCollection.AddSingleton<ExternalAuthService>();
332332
```
333333

@@ -345,7 +345,7 @@ Add the authorization services and Blazor abstractions to the service collection
345345

346346
```csharp
347347
services.AddAuthorizationCore();
348-
services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
348+
services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
349349
services.AddSingleton<ExternalAuthService>();
350350
```
351351

@@ -377,7 +377,7 @@ public class CurrentThreadUserAuthenticationStateProvider : AuthenticationStateP
377377
}
378378
```
379379

380-
Using the alternative approach, only authorization services (<xref:Microsoft.Extensions.DependencyInjection.AuthorizationServiceCollectionExtensions.AddAuthorizationCore%2A>) and `CurrentThreadUserAuthenticationStateProvider` (`.AddScoped<AuthenticationStateProvider, CurrentThreadUserAuthenticationStateProvider>()`) are added to the service collection.
380+
Using the alternative approach, only authorization services (<xref:Microsoft.Extensions.DependencyInjection.AuthorizationServiceCollectionExtensions.AddAuthorizationCore%2A>) and `CurrentThreadUserAuthenticationStateProvider` (`.TryAddScoped<AuthenticationStateProvider, CurrentThreadUserAuthenticationStateProvider>()`) are added to the service collection.
381381

382382
### Handle authentication within the `BlazorWebView` (Option 2)
383383

@@ -451,7 +451,7 @@ In the `MauiProgram.CreateMauiApp` method of `MainWindow.cs`, add the authorizat
451451

452452
```csharp
453453
builder.Services.AddAuthorizationCore();
454-
builder.Services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
454+
builder.Services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
455455
```
456456

457457
:::zone-end
@@ -462,7 +462,7 @@ In the `MainWindow`'s constructor (`MainWindow.xaml.cs`), add the authorization
462462

463463
```csharp
464464
serviceCollection.AddAuthorizationCore();
465-
serviceCollection.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
465+
serviceCollection.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
466466
```
467467

468468
:::zone-end
@@ -473,7 +473,7 @@ In the `Form1`'s constructor (`Form1.cs`), add the authorization services and th
473473

474474
```csharp
475475
services.AddAuthorizationCore();
476-
services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
476+
services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
477477
```
478478

479479
:::zone-end
@@ -492,7 +492,7 @@ The following `LoginComponent` component demonstrates how to log in a user. In a
492492
public async Task Login()
493493
{
494494
await ((ExternalAuthStateProvider)AuthenticationStateProvider)
495-
.LoginAsync();
495+
.LogInAsync();
496496
}
497497
}
498498
```
@@ -545,7 +545,7 @@ When implementing authentication:
545545

546546
::: moniker-end
547547

548-
::: moniker range=">= aspnetcore-7.0"
548+
::: moniker range=">= aspnetcore-6.0 < aspnetcore-7.0"
549549

550550
Authentication in Blazor Hybrid apps is handled by native platform libraries, as they offer enhanced security guarantees that the browser sandbox can't offer. Authentication of native apps uses an OS-specific mechanism or via a federated protocol, such as [OpenID Connect (OIDC)](https://openid.net/connect/). Follow the guidance for the identity provider that you've selected for the app and then further integrate identity with Blazor using the guidance in this article.
551551

@@ -653,7 +653,7 @@ Replace the preceding line of code with the following code. Add OpenID/MSAL code
653653

654654
```csharp
655655
builder.Services.AddAuthorizationCore();
656-
builder.Services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
656+
builder.Services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
657657
builder.Services.AddSingleton<AuthenticatedUser>();
658658
var host = builder.Build();
659659

@@ -701,7 +701,7 @@ Replace the preceding line of code with the following code. Add OpenID/MSAL code
701701

702702
```csharp
703703
serviceCollection.AddAuthorizationCore();
704-
serviceCollection.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
704+
serviceCollection.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
705705
serviceCollection.AddSingleton<AuthenticatedUser>();
706706
var services = serviceCollection.BuildServiceProvider();
707707
Resources.Add("services", services);
@@ -747,7 +747,7 @@ Replace the preceding line of code with the following code. Add OpenID/MSAL code
747747

748748
```csharp
749749
services.AddAuthorizationCore();
750-
services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
750+
services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
751751
services.AddSingleton<AuthenticatedUser>();
752752
var serviceCollection = services.BuildServiceProvider();
753753
blazorWebView1.Services = serviceCollection;
@@ -841,7 +841,7 @@ Add the authorization services and Blazor abstractions to the service collection
841841

842842
```csharp
843843
builder.Services.AddAuthorizationCore();
844-
builder.Services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
844+
builder.Services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
845845
builder.Services.AddSingleton<ExternalAuthService>();
846846
```
847847

@@ -859,7 +859,7 @@ Add the authorization services and the Blazor abstractions to the service collec
859859

860860
```csharp
861861
serviceCollection.AddAuthorizationCore();
862-
serviceCollection.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
862+
serviceCollection.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
863863
serviceCollection.AddSingleton<ExternalAuthService>();
864864
```
865865

@@ -877,7 +877,7 @@ Add the authorization services and Blazor abstractions to the service collection
877877

878878
```csharp
879879
services.AddAuthorizationCore();
880-
services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
880+
services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
881881
services.AddSingleton<ExternalAuthService>();
882882
```
883883

@@ -909,7 +909,7 @@ public class CurrentThreadUserAuthenticationStateProvider : AuthenticationStateP
909909
}
910910
```
911911

912-
Using the alternative approach, only authorization services (<xref:Microsoft.Extensions.DependencyInjection.AuthorizationServiceCollectionExtensions.AddAuthorizationCore%2A>) and `CurrentThreadUserAuthenticationStateProvider` (`.TryAddScoped<AuthenticationStateProvider, CurrentThreadUserAuthenticationStateProvider>()`) are added to the service collection.
912+
Using the alternative approach, only authorization services (<xref:Microsoft.Extensions.DependencyInjection.AuthorizationServiceCollectionExtensions.AddAuthorizationCore%2A>) and `CurrentThreadUserAuthenticationStateProvider` (`.AddScoped<AuthenticationStateProvider, CurrentThreadUserAuthenticationStateProvider>()`) are added to the service collection.
913913

914914
### Handle authentication within the `BlazorWebView` (Option 2)
915915

@@ -983,7 +983,7 @@ In the `MauiProgram.CreateMauiApp` method of `MainWindow.cs`, add the authorizat
983983

984984
```csharp
985985
builder.Services.AddAuthorizationCore();
986-
builder.Services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
986+
builder.Services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
987987
```
988988

989989
:::zone-end
@@ -994,7 +994,7 @@ In the `MainWindow`'s constructor (`MainWindow.xaml.cs`), add the authorization
994994

995995
```csharp
996996
serviceCollection.AddAuthorizationCore();
997-
serviceCollection.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
997+
serviceCollection.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
998998
```
999999

10001000
:::zone-end
@@ -1005,7 +1005,7 @@ In the `Form1`'s constructor (`Form1.cs`), add the authorization services and th
10051005

10061006
```csharp
10071007
services.AddAuthorizationCore();
1008-
services.TryAddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
1008+
services.AddScoped<AuthenticationStateProvider, ExternalAuthStateProvider>();
10091009
```
10101010

10111011
:::zone-end
@@ -1024,7 +1024,7 @@ The following `LoginComponent` component demonstrates how to log in a user. In a
10241024
public async Task Login()
10251025
{
10261026
await ((ExternalAuthStateProvider)AuthenticationStateProvider)
1027-
.LoginAsync();
1027+
.LogInAsync();
10281028
}
10291029
}
10301030
```

0 commit comments

Comments
 (0)