Skip to main content

Sign in with a code

When. Some operations are for known people only: members, customers with an account. The tenant already sends codes (by e-mail or SMS): Convoy uses its two operations to sign the person in.

Steps​

  1. Declare the tenant's two operations in the API, both access: write: one sends the code, the other checks it. Never grant them in a profile.
  2. Declare the provider in station.identity.providers: mechanism: otp, via: tenant, send, check, verifies (the name of the data proved) and type (email or phone).
  3. Ask that data in a form with identifies: true, under the name verifies gives: the room then holds the value, and the code goes to it without the model repeating it.
  4. Open more to the signed-in person with a profile: when: "'email' in $identity.verified" (or $identity.authenticated), and its grants. Grants add up with everyone's.
  5. What the tenant's operations must take and answer: send receives the value under the data's name (email); check receives it and code, in their JSON body, and answers {"verified": true}. Anything else is no.
  6. Check the config. In Claude and ChatGPT, the host's sign-in window asks the e-mail and the code.

The example​

sign-in-with-a-code.yaml
# Sign in with a one-time code: the tenant sends a code to the person's e-mail and checks it, with
# two operations of its own; a right code signs the person in, and a profile opens more operations
# to them. Convoy never sees the code; the model never sees the e-mail. Replace api.example.com by
# the API.
station:
id: member-library
name: Member Library
identity:
idle_minutes: 1440 # a sign-in nobody uses for a day ends
providers:
email:
mechanism: otp
verifies: email # the name of the data proved: a field that identifies
type: email
via: tenant
send: sendVerificationCode # receives {email}; sends the code
check: checkVerificationCode # receives {email, code}; answers {"verified": true}

global:
language: en
currency: EUR
locale: en-GB

domain:
domain_type: saas
entity_name: book
entity_name_plural: books

voice:
tone: friendly
persona: "a librarian who knows every book of the library"
rules:
- "Never say a book is reserved before the submit returned it."

apis:
- name: library
openapi_url: https://api.example.com/openapi.json
base_url: https://api.example.com
operations:
- {id: searchBooks, access: read}
- {id: reserveBook, access: write}
- {id: sendVerificationCode, access: write} # the sign-in's: declared, never granted
- {id: checkVerificationCode, access: write}
auth: {type: none}

profiles:
anyone: # what everyone may do
when: "true"
grants: [library.searchBooks]
members: # what a person signed in may do, on top
when: "'email' in $identity.verified"
grants: [library.reserveBook]

skills:
- name: books
cognitive:
objective: find books, for the person to reserve one
params:
q: {type: text, set_by: [llm]}
invoke:
method: searchBooks
args: {q: "$params.q"}
kinds: {book: {}}
present:
fields:
name: {from: title, type: text, role: title}
author: {from: author, type: text, role: meta}
select:
max_items: 1
guards:
- form:
email: {type: email, required: true, label: "Your member e-mail", identifies: true}
submit:
- name: reserve
mode: request
tool: reserveBook
args:
body.book: "$item.ref"
body.email: "$item.fields.email"
body.idempotency_key: "$action.key"
render: {component: cards}

submit_guard:
confirm: true
submitted_by: [{who: owner}]

The pitfalls​

  • mechanism: otp and via: tenant are the only ones today. Convoy never sends a code itself.
  • verifies names a field that identifies the room (identifies: true on a text, email or phone field).
  • A profile reads the identity only: $identity.authenticated, $identity.verified, $identity.provider, $identity.type. Roles, teams or e-mail domains do not exist yet.
  • A profile no one can hold is refused: 'phone' in $identity.verified with no provider that verifies: phone.
  • For the tenant to answer for the person with their own token, add credential and auth.person: Decide who may do what.
  • The model never sees the e-mail nor the code: it holds sign_in alone.

What Core says, and the fix​

Each sentence below is Core's own, as it answers today (a test keeps them true):

  • "which a form asks for without identifies: true" — fix: add identifies: true to the field verifies names.
  • "today a code is sent and checked by the tenant's own operations only" — fix: via: tenant, with send and check.
  • "no caller can hold this profile today" — fix: read data a provider proves, or $identity.authenticated.
  • "is an identity provider's own operation: proving who calls is not granted" — fix: take send and check out of every grants.

Reference: Proving data: a one-time code, Who is signed in, Profiles.