The sign-in flow
Most triauth operations follow the same three stages. Your application starts it, the user's browser carries it to the authenticator, and your application finishes it.
Stage 1: Request
Call Triauth.authenticate with the user's identifier and your callback URL. The library reads the user's DNS records and returns two strings.
challengeis the request itself, together with the key that decrypts the response. Store it in the user's server-side session, and keep it out of URLs and logs.redirectUrlis the address of the user's authenticator with the request attached. Redirect the browser there.
If the domain is not set up for triauth, or the identifier is malformed, you get an error with a code and a message instead.
This is also where you ask for more than a sign-in. In the same call, you can give your application's name and icon for the user's home screen, and ask for permissions. See Extensions and permissions.
Start this stage only from your own pages. Otherwise another website can post an attacker's identifier to your sign-in form from the user's browser. An authenticator that the attacker runs can approve the request at once, and your website then signs the user in to the attacker's account. This attack is known as login CSRF. Protect the sign-in form as you protect any form that changes state. Require a CSRF token, or refuse the request when its Sec-Fetch-Site header is present and is not same-origin. Browsers set this header to same-origin when the form comes from your own website. Never start this stage from a GET request.
Stage 2: Redirect
The user's browser opens their authenticator. It shows your website's address and the identifier, and asks the user to approve or deny. On approval, the user's device signs the request. The authenticator encrypts the signed response and sends the browser to your callback URL with it, by default as an HTTP GET with a response parameter in the query string. Receiving the response explains when to ask for another method.
Keep the Referer header on the redirect. The authenticator may refuse a request that arrives without one, and it only needs your origin. Do not use rel="noreferrer", and check that security middleware does not set a no-referrer policy.
Stage 3: Verify
Read response from the callback request. Take challenge from your trusted session store. Call Triauth.authenticate with both. The library decrypts the response with the key in the challenge and verifies the signatures. Then delete the challenge from the session, whatever the result.
This call returns a result object. On success, result.authenticated is true, and result.identifier is the verified identifier. On failure, result.error says why.
Upon successful authentication, the result carries the fields below. Store identifier, deviceTag, and sessionKey with the session, and redirect the user away from callbackUrl so that it is not kept in the browser history list.
| Field | Meaning |
|---|---|
authenticated | true for a successful authentication. |
identifier | The verified identifier, in lowercase. Use it as the key of the user's account. |
identityDomain | The DNS name under which the identity records were read. |
lookupCode | The identity's lookup code, for a private-mode domain. Empty otherwise. Needed to look the identity up again. Treat it like the identifier. |
actor | The identifier of the delegate who signed in on the user's behalf. Empty for a direct sign-in. See Delegation. |
actorIdentityDomain | The DNS name under which the actor's records were read. Empty for a direct sign-in. |
actorLookupCode | The actor's lookup code, for a private-mode domain. Empty otherwise. |
deviceName | The public name of the device that signed. For display only. |
deviceTag | A fingerprint of the device, its lookup code, and the delegation used. Store it with the session and use it to re-check the session. A new value means a new device. Do not display it. |
keys | The public keys of the device, as read from DNS, with their options and whether each one was verified or skipped. |
groups | The identity's group names, qualified with the domain and sorted, such as admins@example.com. Empty when none are published. See Groups. |
publicProfile | The name and initials the user published in DNS, if any. Escape them before you render. |
secure | true when DNSSEC protected every record read. Decide what false means for you. |
expires | The time until which the DNS records behind this sign-in count as fresh. A hint for when to re-check, with your own minimum interval. May be missing. |
issuedAt | When you issued the challenge, by your server's clock. |
signedAt | When the device signed the response, by the device's clock. |
verifiedAt | When the response was verified, by your server's clock. |
sessionKey | A secret of this sign-in that only your application and the user's authenticator know. Later requests need it. Store it with the session and keep it out of logs. See Sessions and sign-out. |
ext | Data from the extensions you requested, such as the permissions granted. See Extensions and permissions. |
API reference:JavaScript·Ruby
The callback URL
Choose a fixed callback URL in your configuration. The authenticator remembers your website by the base of this URL - its origin and path up to the last slash - and binds the session key and the permissions of every sign-in to that base.
Account creation and new devices
Use the identifier as the account key. On the first sign-in, create the account. There is no password to set. Compare deviceTag with the devices you have seen for this account. A new device is normal, and it is also the moment to ask for a second factor if your risk profile calls for it.