← Back to projects

work · active

How I Let an AI Assistant Use the Teacher's Login Without Seeing a Password

A teacher signs in to the whiteboard once, and the AI assistant on the same panel knows who they are, without either app ever handing the other a password, token or cookie.

Android · Identity · IPCKotlin · Binder IPC · OAuth 2.0 PKCE · Android Keystore · ContentProvider

Role
Broker author
Duration
Aug 2026
Type
work
Status
active

Key results

  • 0Passwords or tokens passed between the two apps
  • 60 sHow long the one-time sign-in code lasts
  • 4Differently signed versions of the assistant it has to trust

Overview

On a Teachmint classroom panel, teachers sign in to the whiteboard app. In August 2026 our AI assistant needed the same teacher, so nobody would have to sign in twice on a shared screen at the front of a classroom.

I designed and built the sign-in bridge between the two apps. The first design worked and was replaced within days. The reasons it was replaced are most of the story.

The problem

The obvious design is to share what the whiteboard already has: give the assistant the whiteboard’s session cookie, and let it call the API as the teacher.

That version existed. It exported saved accounts and the active session to the assistant through a read-only ContentProvider. It failed in two ways:

  • It broke after a while, without an obvious error. The assistant went “unauthorized” some time after sign-in. The token request returned HTTP 200, but with a failure flag in the body, so the session was already dead. The replayed cookie still looked valid locally, with a far-future expiry, so nothing on the device knew it was dead.
  • It was the wrong security model. A security review made it non-negotiable: the assistant must never read, copy or store a whiteboard credential. Exporting cookies was out, however carefully it was done.

Constraints

  • No shared signing key. The assistant ships four flavours, each signed with a different OEM platform key, and the whiteboard is signed by CI. protectionLevel="signature", the textbook way to restrict an API to your own apps, would deny every real build.
  • No second login. Putting Teachmint credentials into a second app’s own login screen would double the attack surface.
  • A shared device. Teachers switch accounts on the same panel, so whatever the assistant holds has to follow the whiteboard’s account changes.

My approach

The replacement is an identity broker in the whiteboard, reached over Binder, built on the OAuth authorization code flow with PKCE:

Assistant                                  Whiteboard (broker)
  │  bind (caller verified)  ───────────►  SsoCallerGuard
  │  list accounts            ◄──────────  display-only choices, opaque ids
  │  authorize(account, code_challenge) ►  mint a 60-second, PKCE-bound code
  │  ◄──────────── authorization code      (no cookie, no user id)
  │  exchange code + code_verifier ──────► Teachmint backend
  │  ◄──────────── the assistant's own session

The assistant never sees the whiteboard’s credentials. It gets a short-lived code that only it can redeem, because it alone holds the PKCE verifier, and it trades the code for its own session.

Important decisions

Verify callers at runtime, fail closed

With signature permissions ruled out, every exported entry point goes through one guard that checks, in order:

  1. the Binder caller uid, which the kernel attests and can’t be spoofed
  2. that the caller runs as the same user
  3. a package allowlist
  4. a pinned signing certificate per allowed package

Anything that fails a step is refused.

Nothing identifying crosses IPC

  • Opaque account ids. Accounts are shown to the assistant as display-only choices with stable ids derived by an Android Keystore HMAC, not raw user ids.
  • Data-free change signals. When accounts change, the whiteboard broadcasts a signal that carries no data at all. A forged broadcast achieves nothing beyond making the assistant re-read a channel that authenticates it anyway.

Borrow the real login, don’t build a second one

If no one is signed in, the assistant launches the whiteboard’s own login screen, floating over the assistant in a transparent activity, which returns only a result. That exported activity is gated by the same caller guard: an unguarded Teachmint login screen would be a phishing surface. Its launch mode stays standard on purpose. With singleTask, startActivityForResult returns RESULT_CANCELED immediately and getCallingPackage() returns null, which would silently disable the caller check.

What went wrong

Review found real bugs before release:

  • Every request needs exactly one ending. A crash or teardown mid-authorization could leave the assistant waiting forever. The broker now tracks pending requests, catches everything in the authorization path, and answers any unanswered request with “temporarily unavailable” when it’s destroyed.
  • An account switch during the network call. The active profile was read before the code was minted, so a switch mid-request could mint for the wrong teacher. It’s now re-read after.
  • “Nobody signed in” versus “couldn’t read”. A database failure looked the same as no account. They’re now distinct answers.
  • Concurrent broadcasts. Two account changes at once crashed the callback list, so notification is synchronised.
  • Unbounded network calls. The mint now has finite timeouts. The app’s shared HTTP client is unbounded by default.
  • Malformed requests. These got their own terminal status, so clients don’t retry them in a loop.

The ContentProvider from the first design left lessons too. ContentProvider.onCreate runs before Application.onCreate, so it can’t touch the dependency-injection graph. Its getType() isn’t subject to provider permissions, so a data-dependent answer would have been an unauthenticated “is a teacher signed in?” oracle for every app on the device.

Result

The assistant signs in as the teacher on the whiteboard with no credential ever crossing the app boundary. It gets a 60-second, PKCE-bound code and exchanges it for a session of its own, and it follows account changes through a data-free signal.

One debt was accepted knowingly. The hosted login reuses the whiteboard’s login composables as a copy, about 4,000 lines, because refactoring the only working login path was the riskier change. Merging the two copies back is the planned follow-up.

What I learned

  1. Share proof, not credentials. A short-lived, bound code makes the other app a client, not a holder of your secrets.
  2. Signature permissions assume one signing key. With OEM platform keys, verify callers at runtime: Binder uid first, then a pinned certificate.
  3. Exported components need the same scrutiny as a public API. getType(), launch modes and onCreate order all leak or break in non-obvious ways.
  4. HTTP 200 isn’t success when the API reports failure in the body.
  5. Every asynchronous request needs exactly one terminal answer, including when the process dies.