In the previous articles we added protection after protection to the sign-in: state against login CSRF, PKCE against a stolen or injected authorization code, and exact redirect URIs so the authorization code only goes back to the app. With all that in place, a fair question is: why does the BFF still need a client secret? If the redirect URI is exact and PKCE is on, what is left for it to do?
What the client secret is
When an app is registered at the identity provider, it gets a client id (public, it appears in every /authorize URL) and, if it runs on a server, a client secret: a password for the app itself. Whenever the app calls the provider's token endpoint, it sends both, and the provider checks them (RFC 6749, §2.3).
Only apps that can keep a secret get one. OAuth calls them confidential clients: a server, like our BFF. A single-page app or a mobile app is a public client: anything shipped to a browser or a phone can be read by whoever has it, so it can't hold a secret (RFC 6749, §2.1). That's one of the main reasons to have a BFF at all.
Each protection answers a different question
The protections we've seen don't overlap; each one checks something else:
| Protection | The question it answers |
|---|---|
state | Did this browser start this sign-in? |
| PKCE | Is whoever exchanges this authorization code the one who started this sign-in? |
| Exact redirect URI | Does the authorization code go back to the app's own address? |
| Client secret | Is whoever calls the token endpoint the registered app? |
Only the client secret is about the app's identity. The other three are about one sign-in. That difference is what the rest of this article is about.
What the client secret does
The client secret identifies the app to the identity provider. Every time the BFF calls the provider's token endpoint (to exchange an authorization code, refresh a token, or revoke one), it sends its client id and its secret, and the provider checks them. So only the real BFF can make those calls in the app's name.
That gives the provider two things:
- It knows which app is behind each request. It can log it, apply per-app rules (which scopes the app may ask for, how long its tokens last, rate limits), and switch an app off.
- What it issued to an app can only be used by that app. OAuth says this is the purpose of client authentication: to bind authorization codes and refresh tokens to the app they were issued to (RFC 6749, §3.2.1).
Can someone build a fake app?
The client id is no secret: it appears in every /authorize URL, so anyone can copy it and build a fake app that claims to be yours. What can that fake app do?
The other attacks in this series (login CSRF, code injection, the code sent to the wrong place) go through your real app. Here we only look at what a fake app holding your client id can try, and it comes down to two things:
- Getting new authorization codes. The fake app starts a sign-in with your client id and hopes the provider sends the code to it. Here the client secret isn't even needed: with an exact redirect URI (previous article), the provider sends the code to your app's address, never to the fake one. The redirect URI alone stops this.
- Using codes or tokens stolen from your app, such as a refresh token taken from a log or a leaked database. The fake app takes it straight to the token endpoint. The redirect URI can't help here, because nothing is being redirected. What stops it is the client secret: the token endpoint wants proof that the caller is your app. Without a secret, your client id is all it asks for, and anyone has that. With a secret, the fake app is stuck.
So exact redirect URIs keep the fake app from receiving your app's authorization codes, and the client secret keeps it from using anything issued to your app.
1. Refresh tokens
The biggest thing a stolen value can give is a refresh token. Access tokens are short-lived, so the app usually also gets a refresh token: a long-lived token it exchanges for new access tokens without asking you to log in again. Days or weeks of access, in one string.
PKCE plays no part here: it only protects the exchange of an authorization code. So with a client secret, a stolen refresh token alone gets nothing (RFC 6749, §6). Without one (a public client), the refresh token alone is enough, which is why RFC 9700 requires extra measures for public clients' refresh tokens, such as rotating them on every use (§2.2.2).
The same goes for a stolen authorization code when the provider ignores PKCE (a provider that doesn't know PKCE silently ignores the code_challenge): the attacker still can't exchange it directly without the secret. It doesn't stop the code injection from the second article, which goes through the BFF and its own secret.
2. Recovering when something leaks
If the app is compromised, the provider can change its secret or disable it, and every stolen authorization code and refresh token issued to it stops working at once, without touching any user. A public client has no such switch: anyone who copied its client id can keep presenting it.
3. Revoking tokens
When you sign out, the app should tell the provider to throw its refresh token away (the revocation endpoint, RFC 7009). A confidential client must authenticate there too (§2.1), so nobody else can revoke the app's tokens in its name.
What the client secret does not do
- It doesn't replace PKCE: it says nothing about which sign-in an authorization code belongs to, which is why RFC 9700 recommends PKCE for confidential clients too (§2.1.1).
- It doesn't replace
stateor exact redirect URIs: those protect the trip through the browser, where the secret never goes. - It only works while it stays secret. It must live in the server's environment, never in a repository, a front-end bundle or a mobile app. If it leaks, rotate it at the provider.
Providers also offer stronger ways for a server to prove who it is, such as signing a short assertion with a private key instead of sending a shared secret (private_key_jwt, RFC 7523 and OpenID Connect Core §9) or mutual TLS (RFC 8705). The idea is the same: the token endpoint only talks to the real app.
So does a mobile app need a BFF?
Not necessarily. The standard way for mobile apps (RFC 8252, OAuth 2.0 for Native Apps) is a public client: no secret, PKCE, and the login done in the phone's system browser. A phone has what a browser doesn't: secure storage (the Keychain on iOS, the Keystore on Android), where other apps and web pages can't read the tokens. And without a secret, the refresh token is protected by rotation: each refresh returns a new refresh token and invalidates the old one, so a stolen copy stops working as soon as either side uses it (RFC 9700, §2.2.2).
A backend for a mobile app is still a valid choice when you want a confidential client: the tokens never on the phone, or a provider that only gives long-lived refresh tokens to clients with a secret. It's a choice, not a requirement. In the browser the case for a BFF is much stronger, because a browser has no storage that the page's own JavaScript can't read.
Summary
With the right redirect URI and PKCE, the authorization code is safe. The client secret protects what comes after it: the refresh token that keeps you signed in for weeks, the revocation that ends it, and the provider's certainty that it is talking to the real app. That's also why it only makes sense on a server, which is exactly what a BFF is.
References
- RFC 6749, The OAuth 2.0 Authorization Framework, §2.1, §2.3, §3.2.1, §6.
- RFC 7009, OAuth 2.0 Token Revocation, §2.1.
- RFC 8252, OAuth 2.0 for Native Apps.
- RFC 7523, JWT Profile for OAuth 2.0 Client Authentication and Authorization Grants.
- RFC 8705, OAuth 2.0 Mutual-TLS Client Authentication.
- RFC 9700, Best Current Practice for OAuth 2.0 Security, §2.1.1, §2.2.2.
- OpenID Connect Core 1.0, §9 (client authentication).