Back to the journal

Engineering3 min read

One sign-in for everything: how we built auth.dendree.de

Dendree Time, Mail and Accounts now share one sign-in at auth.dendree.de. How two-factor and rights in the token work, and why our first sign-in emails ended up in spam.

Until early October each of our apps had its own sign-in: Dendree Time for time tracking, Dendree Mail and Dendree Accounts. Every new app would have needed another sign-in and another password reset page, and each of those is one more place where something can go wrong. So we built the sign-in once, centrally, at auth.dendree.de.

commits
79
commits
apps behind one sign-in
3
apps behind one sign-in
until a change of rights applies everywhere
1 h
until a change of rights applies everywhere
Dendree Accounts, the app behind auth.dendree.de, in numbers.

How a sign-in works

  1. 01An appNo session: on to the sign-in, with the address to come back to
  2. 02auth.dendree.deEmail or username and password, or a link by email
  3. 03Two-factorA code from the authenticator app, where it is required
  4. 04Back in the appThe session holds for every app under dendree.de
Every app sends people to the same sign-in and gets them back afterwards.

The session sits in a cookie on the whole dendree.de domain. Every app can tell at once that you are already signed in. Sign out in one app and you are signed out in all of them.

The return address needs particular care. If you follow it without checking, you have built an open redirect: a crafted link sends people to someone else’s site right after a genuine sign-in. Ours only leads back to our own site or to HTTPS addresses under dendree.de, and dedicated tests check this.

Signed in is not the same as allowed in

Dendree Accounts decides which app an account may open. So that apps do not have to ask on every request, a small function in the database writes those rights straight into the token you get when you sign in.

{
  "sub": "8f3c…",
  "aal": "aal2",
  "app_access": {
    "time": "member",
    "accounts": "admin"
  },
  "mfa_required": true
}
Part of a sign-in token. Every app only checks whether its key is in there, and with which role.

When an admin changes someone’s rights, the change applies with the next token: at once after signing in again, otherwise within an hour at the latest. An app can also be set to “everyone”, so nobody is locked out while rights are being handed out.

The function that writes rights into the token must never fail.
The most important rule in the Dendree Accounts code

If it does run into an error, the token is issued without rights. Apps that require rights then let nobody in, but the sign-in itself keeps working.

When two-factor is required

For our team and for anyone who is an admin somewhere, the authenticator app is required. Without it, there is no way past the password. Everyone else is offered it once after their first sign-in and can decline. The apps also check this themselves: if the token says two-factor is required and it has not been confirmed, they refuse access.

Sign-in emails in spam

One lesson had nothing to do with security. Our first sign-in emails carried a link with the return address inside it, and GMX kept filing them as spam.

Today the link carries only a one-time code and always leads to the same page, auth.dendree.de/confirm. The browser that requested the email remembers where to go next. Since the change, the emails reach the inbox. The link now also works if you open it in a different browser.

Further details

  • Sign in with a username instead of an email: the server resolves it, the address never reaches the browser.
  • Cloudflare Turnstile protects sign-in, email links and password resets from bots.
  • While sign-up is closed, new accounts are by invitation only. A second function in the database refuses all others.
  • Anyone not allowed into an app sees “No access” instead of an endless loop back to the sign-in.
  • When a token expires, the app tries once with a fresh one before sending you to sign in.
  • Every change to accounts and rights is logged with who made it and when.

What this means for client projects

Many projects end up needing the same thing: several applications behind one sign-in, roles, and two-factor for accounts with far-reaching rights. We run this setup in production every day, and we build it the same way for clients.

More on web platforms

A short conversation is enough to find out whether and how we can help.

With us you get developers as your contacts, a demo every two weeks, documented code, fixed prices for a clear scope, a reply within 24 hours, support after launch

One sign-in for everything: how we built auth.dendree.de – Dendree | Dendree