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
***Authentication flows**: The server handles the authentication flows. There are specific endpoints for login / logout. While the browser is involved with these authentication flows, because the user is redirected to and from the identity provider, the actual browser based application will never see the authentication tokens. These are exchanged for a code on the server only.
33
+
***Cookies**: After successful authentication, a cookie is added. This cookie protects all subsequent calls to the apis. When using this type of authentication, **CSRF protection** is very important.
34
+
***Access to apis**: The BFF can expose embedded apis (which are embedded in the BFF itself) or proxy calls to remote api's (which is more common in a microservice environment). While proxying, it will exchange the authentication cookie for an access token.
35
+
***Session Management**: The BFF can manage the users session. This can either be cookie based session management or storage based session management.
36
+
37
+
38
+
## Internals
27
39
Duende.BFF builds on widely used tools and frameworks, including ASP.NET Core's OpenID Connect and cookie authentication
28
40
handlers, YARP, and Duende.AccessTokenManagement. Duende.BFF combines these tools and adds additional security and
29
41
application features that are useful with a BFF architecture so that you can focus on providing application logic
Copy file name to clipboardExpand all lines: src/content/docs/bff/fundamentals/apis/index.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,10 +15,14 @@ redirect_from:
15
15
16
16
A frontend application using the BFF pattern can call two types of APIs:
17
17
18
-
#### Remote APIs
18
+
#### Embedded (local) APIs
19
19
20
-
These APIs are deployed on a different host than the BFF, which allows them to be shared between multiple frontends or (more generally speaking) multiple clients. These APIs can only be called via the BFF host acting as a proxy.
20
+
These APIs embedded inside the BFF and typically exist to support the BFF's frontend; they are not shared with other frontends or services.
21
+
22
+
See [Embedded apis](local.mdx) for more information.
21
23
22
-
#### Local APIs
24
+
#### Proxying to Remote APIs
25
+
26
+
These APIs are deployed on a different host than the BFF, which allows them to be shared between multiple frontends or (more generally speaking) multiple clients. These APIs can only be called via the BFF host acting as a proxy.
23
27
24
-
These APIs only exist to support the specific frontend; they are not shared with other frontends or services. They are located in the BFF host and can be called directly by the frontend.
28
+
You can use [Direct Forwarding](./remote.md) for most scenarios. If you have more complex requirements, you can also directly interact with [YARP](./yarp.md)
Copy file name to clipboardExpand all lines: src/content/docs/bff/fundamentals/apis/local.mdx
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
-
title: "Local APIs"
3
-
description: Documentation about Local APIs in BFF, including self-contained APIs and those using managed access tokens, along with securing endpoints and configuration details.
2
+
title: "Embedded (local) APIs"
3
+
description: Documentation about Embedded (Embedded) APIs in BFF, including self-contained APIs and those using managed access tokens, along with securing endpoints and configuration details.
A _Local API_ is an API located within the BFF host. Local APIs are implemented with the familiar ASP.NET abstractions of API controllers or Minimal API endpoints.
16
+
An _Embedded API_(or local api) is an API located within the BFF host. Embedded APIs are implemented with the familiar ASP.NET abstractions of API controllers or Minimal API endpoints.
17
17
18
-
There are two styles of local APIs:
18
+
There are two styles of Embedded APIs:
19
19
20
-
- Self-contained Local APIs
21
-
-Local APIs that Make Requests using Managed Access Tokens
20
+
- Self-contained Embedded APIs
21
+
-Embedded APIs that Make Requests using Managed Access Tokens
22
22
23
-
#### Self-Contained Local APIs
23
+
#### Self-Contained Embedded APIs
24
24
25
25
These APIs reside within the BFF and don't make HTTP requests to other APIs. They access data controlled by the BFF itself, which can simplify the architecture of the system by reducing the number of APIs that must be deployed and managed. They are suitable for scenarios where the BFF is the sole consumer of the data. If you require data accessibility from other applications or services, this approach is probably not suitable.
26
26
27
-
#### Local APIs That Make Requests Using Managed Access Tokens
27
+
#### Embedded APIs That Make Requests Using Managed Access Tokens
28
28
29
-
Alternatively, you can make the data available as a service and make HTTP requests to that service from your BFF's local endpoints. The benefits of this style of Local Endpoint include:
29
+
Alternatively, you can make the data available as a service and make HTTP requests to that service from your BFF's Embedded endpoints. The benefits of this style of Embedded Endpoint include:
30
30
31
31
- Your frontend's network access can be simplified into an aggregated call for the specific data that it needs, which reduces the amount of data that must be sent to the client.
32
32
- Your BFF endpoint can expose a subset of your remote APIs so that they are called in a more controlled manner than if the BFF proxied all requests to the endpoint.
33
33
- Your BFF endpoint can include business logic to call the appropriate endpoints, which simplifies your front end code.
34
34
35
-
Your local endpoints can leverage services like the HTTP client factory and Duende.BFF [token management](/bff/fundamentals/tokens) to make the outgoing calls.
35
+
Your Embedded endpoints can leverage services like the HTTP client factory and Duende.BFF [token management](/bff/fundamentals/tokens) to make the outgoing calls.
36
36
37
-
The following is a simplified example showing how local endpoints can get managed access tokens and use them to make requests to remote APIs.
37
+
The following is a simplified example showing how Embedded endpoints can get managed access tokens and use them to make requests to remote APIs.
38
38
39
39
```csharp
40
40
// MyApiController.cs
@@ -66,11 +66,11 @@ public class MyApiController : ControllerBase
66
66
}
67
67
```
68
68
69
-
The example above is simplified to demonstrate the way that you might obtain a token. Real local endpoints will typically enforce constraints on the way the API is called, aggregate multiple calls, or perform other business logic. Local endpoints that merely forward requests from the frontend to the remote API may not be needed at all. Instead, you could proxy the requests through the BFF using either the [simple http forwarder](/bff/fundamentals/apis/remote/) or [YARP](/bff/fundamentals/apis/yarp/).
69
+
The example above is simplified to demonstrate the way that you might obtain a token. Real Embedded endpoints will typically enforce constraints on the way the API is called, aggregate multiple calls, or perform other business logic. Embedded endpoints that merely forward requests from the frontend to the remote API may not be needed at all. Instead, you could proxy the requests through the BFF using either the [simple http forwarder](/bff/fundamentals/apis/remote/) or [YARP](/bff/fundamentals/apis/yarp/).
70
70
71
-
## Securing Local API Endpoints
71
+
## Securing Embedded API Endpoints
72
72
73
-
Regardless of the style of data access used by a local API, it must be protected against threats such as [CSRF (Cross-Site Request Forgery)](https://developer.mozilla.org/en-US/docs/Glossary/CSRF) attacks. To defend against such attacks and ensure that only the frontend can access these endpoints, we recommend implementing two layers of protection.
73
+
Regardless of the style of data access used by a Embedded API, it must be protected against threats such as [CSRF (Cross-Site Request Forgery)](https://developer.mozilla.org/en-US/docs/Glossary/CSRF) attacks. To defend against such attacks and ensure that only the frontend can access these endpoints, we recommend implementing two layers of protection.
74
74
75
75
#### SameSite Cookies
76
76
@@ -221,3 +221,7 @@ MVC controllers and actions can use the `BffApiSkipAntiforgeryAttribute` (which
221
221
publicclassSampleApiController : ControllerBase
222
222
{ /* ... */ }
223
223
```
224
+
225
+
:::note
226
+
It's also possible to disable anti-forgery protection using _BffOptions.DisableAntiForgeryCheck()_
A _Remote API_ is an API that is deployed separately from the BFF host. Remote APIs use access tokens to authenticate and authorize requests, but the frontend does not possess an access token to make requests to remote APIs directly. Instead, all access to remote APIs is proxied through the BFF, which authenticates the frontend using its authentication cookie, gets the appropriate access token, and forwards the request to the Remote API with the token attached.
15
18
16
19
There are two different ways to set up Remote API proxying in Duende.BFF. This page describes the built-in simple HTTP forwarder. Alternatively, you can integrate Duende.BFF with Microsoft's [YARP](/bff/fundamentals/apis/yarp) reverse proxy, which allows for more complex reverse proxy features provided by YARP combined with the security and identity features of Duende.BFF.
17
20
18
-
## Simple HTTP forwarder
21
+
## Direct HTTP forwarding
19
22
20
-
Duende.BFF's simple HTTP forwarder maps routes in the BFF to a remote API surface. It uses [Microsoft YARP](https://github.com/microsoft/reverse-proxy) internally, but is much simpler to configure than YARP. The intent is to provide a developer-centric and simplified way to proxy requests from the BFF to remote APIs when more complex reverse proxy features are not needed.
23
+
Duende.BFF's direct HTTP forwarder maps routes in the BFF to a remote API surface. It uses [Microsoft YARP](https://github.com/microsoft/reverse-proxy) internally, but is much simpler to configure than YARP. The intent is to provide a developer-centric and simplified way to proxy requests from the BFF to remote APIs when more complex reverse proxy features are not needed.
21
24
22
25
These routes receive automatic anti-forgery protection and integrate with automatic token management.
23
26
24
27
To enable this feature, add a reference to the *Duende.BFF.Yarp* NuGet package, add the remote APIs service to the service provider, and then add the remote endpoint mappings.
25
28
29
+
:::note
30
+
The BFF multi-frontend feature has built-in support for direct forwarding.
31
+
:::
32
+
26
33
#### Add Remote API Service to Service Provider
27
34
28
35
To use the HTTP forwarder, register it in the service provider:
@@ -41,11 +48,24 @@ Use the `MapRemoteBffApiEndpoint` extension method to describe how to map reques
41
48
42
49
The `MapRemoteBffApiEndpoint` extension method maps a path and all sub-paths below it. The intent is to allow easy mapping of groups of URLs. For example, you can set up mappings for the `/users`, `/users/{userId}`, `/users/{userId}/books`, and `/users/{userId}/books/{bookId}` endpoints without having to explicitly include all of them:
This example opens up the complete */users* API namespace to the frontend, and thus, to the outside world. While it is convenient to register API paths this way, consider if you need to be more specific hen designing the forwarding paths to prevent accidentally exposing unintended endpoints.
Copy file name to clipboardExpand all lines: src/content/docs/bff/fundamentals/blazor/rendering-modes.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ It's important to understand that, if you use a rendering mode that uses WebAsse
25
25
26
26
If you have a component that's rendered both on the server AND on the client, then you effectively need to make sure that all the services it requires are available both on the server AND on the client.
27
27
28
-
## Fetching Data From Local APIs
28
+
## Fetching Data From Embedded APIs
29
29
30
30
If your BFF application can directly access data (for example from a database), then you have to decide where this information is rendered.
31
31
@@ -35,11 +35,11 @@ For web assembly rendering, you'll need to make the data available via a web ser
35
35
36
36
When using auto-rendering mode, you'll need to make sure that the component get's a different 'data access' component for server rendering vs client rendering. Consider the following diagram:
In this diagram, you'll see the example **IDataAccessor** that has two implementations. One that accesses the data via an HTTP client (for use in WASM) and one that directly accesses the data.
41
41
42
-
The data is also exposed (and secured by the BFF) via a local api.
42
+
The data is also exposed (and secured by the BFF) via an embedded api.
43
43
44
44
Below is an example of registering an abstraction
45
45
@@ -68,7 +68,7 @@ internal class ServerWeatherClient() : IDataAccessor
68
68
```csharp
69
69
// setup on the client
70
70
71
-
// Register a http client that can access the data via a local api.
71
+
// Register a http client that can access the data via an embedded api.
0 commit comments