Krzysztof TalarFull-Stack .NET Developer
← All case studies

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.

0passwords stored on users’ phones
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.

  1. 1The app sends the login and password to the backend.
  2. 2The backend signs the user in with the partner.
  3. 3The partner returns a session ID.
  4. 4The backend issues its own 7-day token, with no refresh token.
  5. 5The app stores the password on the device so it can sign in again.
  6. 6The partner session expires before the token does.
  7. 7The user is unexpectedly signed out.
  8. 8After a restart the app signs in again with the stored password, even after “signing out”.
  1. 1The app sends the login and password only at sign-in.
  2. 2The backend encrypts the password with Data Protection, keys protected in Azure Key Vault.
  3. 3The backend signs the user in with the partner.
  4. 4The session ID goes to the database, not into the token.
  5. 5The app gets a short access token and a refresh token. It never sees the password again.
  6. 6The partner session expires, as before.
  7. 7The backend signs in again (one attempt, under a lock) and retries the request.
  8. 8The user notices nothing.
  9. 9Sign-out revokes the tokens and the partner session. For real this time.

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.