oauth-2.0oauthpkce

BFF pattern for native apps in OAuth 2.0?


I've read through all of the following RFCs:

[3] recommends the use of one of the following architectures for browser-based applications:

[3] also recommends the BFF pattern especially for sensitive applications:

This architecture is strongly recommended for business applications, sensitive applications, and applications that handle personal data.

On the contrary, [2] (throughout the RFC but especially in Section 4.1) only refers to the architecture where no backend is involed in OAuth 2.0, which conceptually corresponds to the Browser-based OAuth 2.0 client pattern above.

But why? I have these three questions:


Solution

  • Is it recommended to use the BFF pattern also for native applications?

    I would say no, but there are caveats that I attempt to explain below. BFF is an overloaded term. I would begin by understanding the execution environment and the problems you want a BFF to solve.

    For a browser-based app, a BFF that issues secure cookies ensures that tokens cannot be exfiltrated and thus limits the impact of XSS exploits.

    For a native app, I will use an example where you want to keep tokens returned to devices confidential, since that can also be a motivation for a BFF, to prevent the app or other parties from reading data in JWT access tokens.

    Solutions to both could use backend components but there are major differences. Usually the term BFF is used in the context of browser based apps and not native apps.

    Is there any formal source (such as another RFC) to support your answer?

    Why does [2] not refer to the BFF pattern?

    To see why, let's look at the problems a BFF solves for browser-based applications, where a server component assists the frontend in its security:

    Although you could use a BFF for a native app, you can't hide tokens or cookies from the app's code or dictate where the frontend can send them. Instead, a BFF for a native app might introspect opaque access tokens then forward JWT access tokens to APIs.

    Summary

    I think of a BFF solution as one that involves deploying an extra cookie issuing component per web app. You don't need to do that for native apps.

    Where possible I would manage tasks like token introspection in an API gateway, to apply such logic to multiple APIs. Some people call that type of solution a BFF.