You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IntheServerapp's `Startup.Configure` method, replace `endpoints.MapFallbackToFile("index.html")` with `endpoints.MapFallbackToPage("/_Host")`:
349
+
350
+
```csharp
351
+
app.UseEndpoints(endpoints=>
352
+
{
353
+
endpoints.MapControllers();
354
+
endpoints.MapFallbackToPage("/_Host");
355
+
});
356
+
```
357
+
358
+
IntheServerapp, createa*Pages*folderifitdoesn't exist. Create a *_Host.cshtml* page inside the Server app's*Pages*folder. PastethecontentsfromtheClientapp's *wwwroot/index.html* file into the *Pages/_Host.cshtml* file. Update the file'scontents:
Wedon't recommend this approach. This approach requires treating the third-party access token as if it were generated for a public client. In OAuth terms, the public app doesn'thaveaclientsecretbecauseitcan't be trusted to store secrets safely, and the access token is produced for a confidential client. A confidential client is a client that has a client secret and is assumed to be able to safely store secrets.
*Similarly, refreshtokensshouldn't be issued to a client that isn'ttrusted, asdoingsogivestheclientunlimitedaccessunlessotherrestrictionsareputintoplace.
410
+
411
+
#### Make API calls from the client to the server API in order to call third-party APIs
Copy file name to clipboardExpand all lines: aspnetcore/security/blazor/webassembly/index.md
+4-126Lines changed: 4 additions & 126 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Learn how to secure Blazor WebAssemlby apps as Single Page Applicat
5
5
monikerRange: '>= aspnetcore-3.1'
6
6
ms.author: riande
7
7
ms.custom: mvc
8
-
ms.date: 04/19/2020
8
+
ms.date: 04/22/2020
9
9
no-loc: [Blazor, SignalR]
10
10
uid: security/blazor/webassembly/index
11
11
---
@@ -47,129 +47,7 @@ The `Microsoft.AspNetCore.Components.WebAssembly.Authentication` library offers
47
47
* If the authentication process completes successfully, the user is authenticated and optionally sent back to the original protected URL that the user requested.
48
48
* If the authentication process fails for any reason, the user is sent to the login failed page (`/authentication/login-failed`), and an error is displayed.
49
49
50
-
## Support prerendering with authentication
50
+
## Additional resources
51
51
52
-
After following the guidance in one of the hosted Blazor WebAssembly app topics, use the following instructions to create an app that:
53
-
54
-
* Prerenders paths for which authorization isn't required.
55
-
* Doesn't prerender paths for which authorization is required.
56
-
57
-
In the Client app's `Program` class (*Program.cs*), factor common service registrations into a separate method (for example, `ConfigureCommonServices`):
In the Server app's `Startup.Configure` method, replace `endpoints.MapFallbackToFile("index.html")` with `endpoints.MapFallbackToPage("/_Host")`:
106
-
107
-
```csharp
108
-
app.UseEndpoints(endpoints=>
109
-
{
110
-
endpoints.MapControllers();
111
-
endpoints.MapFallbackToPage("/_Host");
112
-
});
113
-
```
114
-
115
-
In the Server app, create a *Pages* folder if it doesn't exist. Create a *_Host.cshtml* page inside the Server app's *Pages* folder. Paste the contents from the Client app's *wwwroot/index.html* file into the *Pages/_Host.cshtml* file. Update the file's contents:
116
-
117
-
* Add `@page "_Host"` to the top of the file.
118
-
* Replace the `<app>Loading...</app>` tag with the following:
## Options for hosted apps and third-party login providers
134
-
135
-
When authenticating and authorizing a hosted Blazor WebAssembly app with a third-party provider, there are several options available for authenticating the user. Which one you choose depends on your scenario.
136
-
137
-
For more information, see <xref:security/authentication/social/additional-claims>.
138
-
139
-
### Authenticate users to only call protected third party APIs
140
-
141
-
Authenticate the user with a client-side OAuth flow against the third-party API provider:
* The app can only call protected third-party APIs.
152
-
153
-
### Authenticate users with a third-party provider and call protected APIs on the host server and the third party
154
-
155
-
Configure Identity with a third-party login provider. Obtain the tokens required for third-party API access and store them.
156
-
157
-
When a user logs in, Identity collects access and refresh tokens as part of the authentication process. At that point, there are a couple of approaches available for making API calls to third-party APIs.
158
-
159
-
#### Use a server access token to retrieve the third-party access token
160
-
161
-
Use the access token generated on the server to retrieve the third-party access token from a server API endpoint. From there, use the third-party access token to call third-party API resources directly from Identity on the client.
162
-
163
-
We don't recommend this approach. This approach requires treating the third-party access token as if it were generated for a public client. In OAuth terms, the public app doesn't have a client secret because it can't be trusted to store secrets safely, and the access token is produced for a confidential client. A confidential client is a client that has a client secret and is assumed to be able to safely store secrets.
164
-
165
-
* The third-party access token might be granted additional scopes to perform sensitive operations based on the fact that the third-party emitted the token for a more trusted client.
166
-
* Similarly, refresh tokens shouldn't be issued to a client that isn't trusted, as doing so gives the client unlimited access unless other restrictions are put into place.
167
-
168
-
#### Make API calls from the client to the server API in order to call third-party APIs
169
-
170
-
Make an API call from the client to the server API. From the server, retrieve the access token for the third-party API resource and issue whatever call is necessary.
171
-
172
-
While this approach requires an extra network hop through the server to call a third-party API, it ultimately results in a safer experience:
173
-
174
-
* The server can store refresh tokens and ensure that the app doesn't lose access to third-party resources.
175
-
* The app can't leak access tokens from the server that might contain more sensitive permissions.
52
+
* Articles under this *Overview* provide information on authenticating users in Blazor WebAssembly apps against specific providers.
0 commit comments