Decision · 02·Security·2025·3 min read
Secure sign-in on top of a partner API that cannot be changed
An external API that cannot be changed, three ADRs and a token server on OpenIddict.
- My role
- Sole backend developer, from decision to rollout
- When
- October–December 2025
- Stack
- ASP.NET Core · OpenIddict · Azure Key Vault · PostgreSQL
Problem
- Password on the phone. The app kept the user’s password in device storage and signed in with it again whenever it needed to.
- Fake sign-out. After “signing out” and restarting, the app could sign the user straight back in with the stored password.
- Unexpected sign-outs. When the session in the partner’s system expired, the user was kicked out of the app.
Constraint
User accounts live in the partner’s system. Its API requires a login and password for every sign-in, and I could not change that. The app had always signed users in natively, with its own screen.
Decision
Before writing code, I wrote the decision down in three ADRs: how to move sign-in and the partner session to the backend, how to store passwords safely and where to keep the session. For the session I chose PostgreSQL over Redis: the database was already paid for and backed up, and the speed difference did not matter at this traffic level.
The app now sends the login and password only at sign-in and gets a short-lived access token and a refresh token (OpenIddict). The backend renews the partner session on its own, in the background.
Trade-off
The partner needs the password, so it cannot be hashed. The backend keeps it encrypted in two layers: ASP.NET Core Data Protection encrypts the password, its keys live in Azure Blob Storage, separate from the database, and are themselves encrypted with a master key in Azure Key Vault. Keys rotate automatically every 90 days, and the password never goes back to the app. The OAuth password grant matches the native sign-in the app already had. Authorization Code with PKCE would have changed the sign-in screen without removing the password from the system.
Rollout
The old and new models ran side by side thanks to API versions. Nobody had to be signed out or forced to update: users moved to the new sign-in the first time they opened the new app version.
Result
- Passwords are no longer stored on phones.
- Signing out really signs you out: it revokes the tokens and the partner session.
- An expired partner session renews in the background, and the user never notices.
In 2026 I built external partners’ access to the user session on the same model (ADR-004): a partner fetches the session from the API with a role-based API key, and the session never travels through a URL or the app.
Direction
The end goal is token-based sign-in on the partner’s side. Then the password leaves the system entirely. This direction is recorded in the ADR.
Client names and details that would identify them are withheld under NDA.
Next story · Ownership