Dev.to Security 🔐 Cybersecurity 👁 0 📖 6 min read

Open-Sourcing "login-billing," a Shared Login and Billing Foundation That Keeps Customer Data Off Your Servers

! This article is a repost from I started using Claude Code. When you develop and operate multiple apps and web services as an individual, every product requires login and billing. If you save users' email addresses an

Open-Sourcing "login-billing," a Shared Login and Billing Foundation That Keeps Customer Data Off Your Servers

!

This article is a repost from I started using Claude Code.

When you develop and operate multiple apps and web services as an individual, every product requires login and billing. If you save users' email addresses and contract information on your own server each time, you carry the risk of information leakage forever.

So, based on the principle of "what you don't have can't leak," I built login-billing, a common login and billing foundation that keeps no customer information on your own server at all. I also put together guidelines for screen placement when integrating it into products, as well as for device migration. The source code is published on GitHub under the MIT license.

A design that started from "what you don't have can't leak"

The starting point was to reduce the risk of customer personal information leaking from my own server to zero. I accepted the premise that trusted giants like Apple and Google store accounts and payments, and designed things so that no information about customers remains on my own server.

I narrowed billing down to the App Store and Google Play. Stripe itself doesn't have a purchaser login feature, so linking login and subscription would remain on my own server. With the App Store and Google Play, the device account and purchase information are tied together directly. While accepting the 15% fee and the constraint that people without an iPhone, Mac, or Android can't purchase directly, I decided on a policy of preparing dedicated smartphone apps even for products that don't have a smartphone app.

Another decision was to not set up a central server that handles authentication and billing all together, but instead to make it a common library that gets integrated into each product. It runs independently per product, and the same user isn't linked across products.

The evolution of the design as I stripped down the server

While testing on real devices, I trimmed down the server's role step by step.

In the initial design, I was thinking of signing in with just a smartphone, and having PCs and the web receive a 14-day-valid pass from the server via a QR code. However, I realized that to prevent relay attacks where someone gets you to accidentally scan their QR code, it's more defensible for PCs and the web to also sign in to Apple or Google themselves, and to limit approval to the same account.

From there, I went further and completely removed my own server from login and billing confirmation itself. Both sign-in and store billing confirmation are completed within the device. Devices without a store, like Windows and Linux, sign in to Apple or Google themselves and then display a QR code. A parent smartphone signed in with the same account scans that QR code and returns approval directly over the same LAN. The return destination when signing in to Apple from Windows is handled by just placing a single static blank page that doesn't send any information to a server.

An overview of all 4 patterns. Organized into 4: operator hosting, free installation by users, parent-smartphone-only, and team-based billing.

An overview of all 4 patterns. Organized into 4: operator hosting, free installation by users, parent-smartphone-only, and team-based billing.

What I prepared for products that need a server was the "keyhole" mechanism. Each device creates an encryption key that never leaves the device, and the server holds only a random identifier, the device's public key, and the parent/child role. It doesn't hold names, email addresses, Apple or Google account IDs, billing status, or IP address records.

While testing on real devices with an iPhone, iPad, and Mac, I noticed something odd: even with the same Apple ID, each device ended up with a different entry point. So I limited each entry point to one parent, and arranged things so that simply reading a QR code with the parent smartphone's standard camera opens the app. Also, since it works as-is even in environments with a mix of wired LAN and Wi-Fi, I changed the guidance text from "same Wi-Fi" to "same network (same LAN)."

After that, for products that handle shared data among multiple people, I also integrated into the common foundation a team model where people join via an invite URL and a QR code that changes every 5 minutes, and a single representative smartphone handles the store billing.

Screen placement guideline: "one layer for parents, two layers for children"

As I integrated the common library into multiple products, situations emerged where users got confused depending on how screens were placed. In an Android app, the child device's join button was hidden behind Google login, and problems actually occurred where someone who had been using it on iPhone couldn't get in from Android, or was asked to log in twice.

So I put together a screen placement guideline and made "one layer for parents, two layers for children" the common rule.

The main login screen (1st layer) shows, without prior login, a parent button corresponding to that device's store (Apple devices: Apple, Android: Google) and a "Join from another device" button. For products with a store's initial free trial period, this is explained on the main login screen.

Mock of the 1st-layer main login screen. The parent button for the device's own OS and "Join from another device" are shown without prior login.

Mock of the 1st-layer main login screen. The parent button for the device's own OS and "Join from another device" are shown without prior login.

After pressing "Join from another device" (2nd layer), both Apple and Google are shown. Just pressing the chosen button once takes you from sign-in to QR code display, so you're never asked to log in twice. Devices without a store, like the web, Windows, and Linux, only show the child join entry point.

Mock of the 2nd-layer child join screen. Choose from both Apple and Google, and a single sign-in takes you to QR code display.

Mock of the 2nd-layer child join screen. Choose from both Apple and Google, and a single sign-in takes you to QR code display.

This screen placement is published as a screen placement and device migration guide where you can actually press the buttons in a browser to check the transitions and the number of API calls.

Device migration and the decision when all devices are lost

The last thing I nailed down in the design that keeps no personal information on the server was device migration.

In a normal device migration where the old parent smartphone is still at hand, the new smartphone displays a QR code for parent handover, and the old parent's camera reads it to transfer the parent role. If the old parent is lost or breaks down, you re-sign in to the same Apple or Google account on a registered child device (PC, browser, another smartphone, etc.) and promote that child device to parent. You just remove the old parent's keyhole and take over the same data and the other child devices as-is.

The remaining case is when the parent device and all registered child devices are lost at the same time. If we left an account identifier on the server, we could create a recovery path, but that would break the "what you don't have can't leak" principle. So I chose a policy of not recovering data on the server when both the parent and all children are lost. The store subscription itself can be managed and restored in the App Store or Google Play.

Instead, I made the following 3 implementations mandatory for all products that adopt the common foundation.

  1. Before billing, strongly state that this is a personal information protection policy in which the operator's server holds absolutely no personally identifiable information, encrypted or not, and that therefore if you lose both the parent and child devices, data on the server cannot be recovered, and recommend registering a backup child device.
  2. For normal device migration where the old parent is still at hand, provide a feature to hand over the parent via QR code.
  3. When the old parent is lost or breaks down, provide a feature to promote a registered child device to parent.

Common rules for device migration. Three are mandatory: warning/disclaimer at the time of billing, parent handover via QR, and promotion from child to parent.

Common rules for device migration. Three are mandatory: warning/disclaimer at the time of billing, parent handover via QR, and promotion from child to parent.

Supported environments and public repository

login-billing bundles into a single repository: TypeScript for the server and web, Swift for iPhone/iPad/Mac, Kotlin for Android, and even a .NET Android version and a Windows/Linux desktop version. Adopting products specify the version and checksum and integrate it as-is, maintaining the boundary that the mechanism itself is not rewritten in each product.

The source code and design diagrams are published under the MIT license at GitHub (kitepon/login-billing). You can check the differences among the 4 patterns and the screen transitions by actually pressing through them in the screen placement and device migration guide.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.