Authentication
Email confirmation, sign-in links and change of email
Four flows that go through a person's mailbox. All of them need email to be set up for the project (the project's Emails page shows whether it is), and the first three also need a Site URL or a listed redirect address.
How every flow works
A link in one of these emails never does anything by being opened. It leads to your application's own address with two query values:
https://app.example.com/welcome?rezin_type=signup&rezin_token=…
Your page reads them and calls POST /v1/auth/verify with your publishable key. So a mail scanner that opens every link confirms nothing.
- Requests that send an email answer the same way whether or not the address has an account:
202 { "sent": true }. - Links for confirming sign-up and changing email last 60 minutes. Sign-in links and codes last 10 minutes.
- Each works once, and a newer request cancels the older one.
- A six-digit code is dead after five wrong tries.
- Only hashes of links and codes are stored.
| Flow | Switch it on | Start | Finish |
|---|---|---|---|
| Confirm sign-up | Authentication → Sign-in methods → "New accounts must confirm their email address first" | POST /v1/auth/signup | POST /v1/auth/verify with type: "signup" |
| Sign-in link or code | Authentication → Sign-in methods → "Sign-in link by email" | POST /v1/auth/magiclink | POST /v1/auth/verify with type: "magiclink" |
| Change of email | always available | POST /v1/auth/email | POST /v1/auth/verify with type: "email_change" |
| Confirm it is you | always available | POST /v1/auth/reauthenticate | POST /v1/auth/reauthenticate/verify |
Both switches are off for a new project.
Confirm sign-up
With the switch on, POST /v1/auth/signup creates nothing. It answers 202 { "confirmationRequired": true } and emails a link. The account appears when your page finishes the flow:
curl -s $API/v1/auth/verify -H "apikey: $KEY" -H "content-type: application/json" \
-d '{"type":"signup","token":"<rezin_token from the link>"}'
{ "confirmed": true, "id": "5b0c1d8e-3f7a-4c2b-9e1d-6a7b8c9d0e1f" }
The person then signs in as usual. redirectTo on the sign-up request chooses which of the project's listed addresses the link leads to; without it, the Site URL is used.
| Status | Code | When |
|---|---|---|
| 409 | site_url_required | The project has no Site URL, or redirectTo is not on its list |
| 503 | email_not_ready | Email is not set up for the project |
| 401 | bad_code | The link has expired, was already used, or is not right |
| 409 | email_in_use | The address got an account in the meantime |
Sign-in link or code
POST /v1/auth/magiclink
curl -s $API/v1/auth/magiclink -H "apikey: $KEY" -H "content-type: application/json" \
-d '{"email":"[email protected]","redirectTo":"https://app.example.com/signed-in"}'
{ "sent": true }
The email carries a six-digit code, and a link when the project has an address to send people back to. Finish with either:
# from the link
curl -s $API/v1/auth/verify -H "apikey: $KEY" -H "content-type: application/json" \
-d '{"type":"magiclink","token":"<rezin_token>"}'
# or from the code the person typed
curl -s $API/v1/auth/verify -H "apikey: $KEY" -H "content-type: application/json" \
-d '{"type":"magiclink","email":"[email protected]","code":"123456"}'
The answer is a session, the same shape as POST /v1/auth/signin.
An account that uses an authenticator app answers 401 code_required. Ask for the 6-digit code and send the same request again with "secondStepCode": "123456" added. The link or code is used up only when the sign-in succeeds. A wrong authenticator code is 401 bad_second_step.
A sign-in link signs in an existing account. It does not create one.
| Status | Code | When |
|---|---|---|
| 403 | method_off | The project does not use sign-in links |
| 400 | bad_redirect | redirectTo is not on the project's list |
| 503 | email_not_ready | Email is not set up for the project |
| 401 | bad_code | Expired, already used, or not right |
Change of email
The user must be signed in, and must prove it is them: either send their current password, or confirm it is you first.
POST /v1/auth/email
curl -s $API/v1/auth/email -H "apikey: $KEY" -H "authorization: Bearer $TOKEN" \
-H "content-type: application/json" \
-d '{"newEmail":"[email protected]","password":"a long passphrase here"}'
{ "sent": true }
A link goes to the new address. Nothing changes until your page finishes:
curl -s $API/v1/auth/verify -H "apikey: $KEY" -H "content-type: application/json" \
-d '{"type":"email_change","token":"<rezin_token>"}'
{ "changed": true }
The old address is then told that the address was changed.
| Status | Code | When |
|---|---|---|
| 403 | confirm_first | No password sent and no fresh "confirm it is you" |
| 409 | site_url_required | No Site URL, or redirectTo not on the list |
| 409 | email_in_use | The new address already has an account |
| 503 | email_not_ready | Email is not set up for the project |
Confirm it is you
For a sensitive step in your own application, or in place of the password when changing email. The user must be signed in.
curl -s -X POST $API/v1/auth/reauthenticate -H "apikey: $KEY" -H "authorization: Bearer $TOKEN"
{ "sent": true }
A six-digit code is emailed to the account's own address. Then:
curl -s $API/v1/auth/reauthenticate/verify -H "apikey: $KEY" -H "authorization: Bearer $TOKEN" \
-H "content-type: application/json" -d '{"code":"123456"}'
{ "ok": true, "validForMinutes": 10 }
The confirmation is good for 10 minutes, on that one sign-in.