Skip to content
Trustaige Docs

Offer Trustaige beside other sign-in methods

Keep your other ways in and still protect what matters. Countersign risky actions, guard the first link, and let customers sign in only with Trustaige.

View as Markdown

Many apps offer Trustaige beside other ways in, such as email codes or other providers. An account is only as strong as its weakest way in: a sign-in through another method keeps that method’s weaknesses, whatever else the account offers. Trustaige can still protect what matters on every account, whichever way the customer came in.

Every button that starts a Trustaige sign-in names Trustaige, as in Name Trustaige on the button.

1. Know which sessions came through Trustaige

When your callback signs a customer in through Trustaige, record that on your session. Use it to decide what each session may do: a session from another method gets your usual trust, and the actions in the next section ask for Trustaige whichever way the customer came in.

2. Countersign what matters

Ask for a countersignature before the actions that move money or change how the account is reached. Include changes to the account’s ways in: adding or removing a sign-in method, and linking or replacing a Trustaige Identity. Someone who gets in through a weaker method then holds a session, but can’t move money or take over the account.

Countersign asks for the sub you hold for the customer. A customer who hasn’t linked Trustaige yet links it at that moment, as in the next section, and then countersigns.

A signed-in customer links their account through the sign-up request from Sign up with a button. Trustaige opens their account with you and returns a sub, and you save it on the customer who started the link.

  1. Ask the customer to sign in again. Linking adds a way into the account, so treat it like changing the account’s email: offer it only within a few minutes of the customer signing in the way they do today, and ask them to sign in again otherwise. A stolen session cookie then can’t link someone else’s Trustaige Identity to the account.

  2. Send the sign-up request with prompt=create, and keep the customer’s ID with the state, nonce and PKCE verifier.

    func (a *Auth) Link(w http.ResponseWriter, r *http.Request) {
        customer, ok := a.recentlySignedIn(r, 5*time.Minute) // signed in moments ago
        if !ok {
            http.Redirect(w, r, "/signin?then=link", http.StatusFound)
            return
        }
        txn := a.newTxn(r) // state, nonce, PKCE verifier
        txn.LinkCustomerID = customer.ID
        a.saveTxnCookie(w, txn)
        url := a.oauth2.AuthCodeURL(txn.State,
            oidc.Nonce(txn.Nonce),
            oauth2.S256ChallengeOption(txn.Verifier),
            oauth2.SetAuthURLParam("prompt", "create"))
        http.Redirect(w, r, url, http.StatusFound)
    }
  3. Save the sub in the callback. In the callback from Sign people in and out, after the ID token is verified and before the lookup by sub, save the sub on the customer who is still signed in:

    if txn.LinkCustomerID != "" {
        customer, ok := a.signedInCustomer(r)
        if !ok || customer.ID != txn.LinkCustomerID {
            a.fail(w, r, "mismatch")
            return
        }
        // Sets subject only where it is empty; the unique column refuses a
        // sub that already belongs to another customer.
        if err := a.store.LinkSubject(r.Context(), customer.ID, idToken.Subject); err != nil {
            a.fail(w, r, "link_taken")
            return
        }
        a.announceLink(r.Context(), customer) // email with a cancel link
        http.Redirect(w, r, "/settings/sign-in?linked=1", http.StatusFound)
        return
    }

What the customer sees on Trustaige’s page is the same as for a sign-up: a customer new to Trustaige creates their Trustaige Identity, one who already has one uses it, and one who linked before confirms it’s them and returns the same sub.

Offer the link in account settings as Continue with Trustaige, and at the moment Countersign needs it. A customer who clicks Sign in with Trustaige before linking comes back with reason=no_account: tell them to sign in the way they did before and link their account, and take them straight to the link after that sign-in.

Signing in again stops a stolen session cookie, but not someone who can sign in through the other method themselves. They could link their own Trustaige Identity and countersign as the customer. Guard the first link:

  • Tell the customer. Email the account’s address when Trustaige is linked, with a link that cancels it.
  • Wait before trusting it. For a waiting period, such as 72 hours, a new link signs in but doesn’t countersign or change how the account is reached. A cancellation in that time removes the link.
  • Replace it only with a countersignature. Once a link has passed its wait, removing it or linking another Trustaige Identity needs a countersignature from the current one.

4. Let customers sign in only with Trustaige

Offer a setting on the account: Sign in only with Trustaige. While it’s on, your app refuses every other way in for that account, including those methods’ own recovery, such as a reset email. Answer a refused attempt as you answer any failed one, so your form doesn’t reveal the setting. Turning it off needs a countersignature.

Customers who want the full protection get it, while your app keeps its other methods for everyone else.

Next: offer an account by link.