Let Users Sign In to Write Reviews

The Open Reviews signer at signer.mangrove.reviews holds a signing key for every person who logs in, with an account they already have or with a passkey, and signs reviews with that key on the person’s behalf. An app that uses it manages no keys. Three calls give it a session, a signed review, and a submission to the open dataset. A person who logs in again later, from any device or any app, gets the same key, so their reviews stay under one identity.

The signer accepts logins through OAuth providers and through passkeys. The provider names are osm for OpenStreetMap, bluesky for an AT Protocol account, and passkey. The Mangrove signer offers these three. The signer software also defines google and github, which a signer can enable later by registering an OAuth app at the provider; a provider that is not enabled answers a login request with 400. bluesky and passkey are always enabled, since neither needs a credential at another service. An account holds several logins: a person who logged in with OpenStreetMap can add a passkey and later drop OpenStreetMap.

Register your app

Every app has a client id and a list of allowed redirect URIs. The signer sends users back only to a URI on that list, matched exactly, so include every callback URL your app uses, including local ones for development.

To get a client id, open an issue in the Mangrove repository or ask in the Open Reviews Matrix room with your app’s name and its redirect URIs.

Install the client

The signer calls are the signer module of the mangrove-reviews package. They make plain HTTP calls, so they run in a browser or in Node.

npm install mangrove-reviews

Every function takes the signer and reviewer API URLs as optional trailing arguments, which default to the public servers. Apps in other languages call the endpoints in the signer’s OpenAPI document; the signer allows requests from any origin.

Send the user to log in

Build the login URL with your client id, the callback URL the user should return to, the provider, and a random state value kept in the browser, then redirect the browser to it:

import { loginUrl } from 'mangrove-reviews/signer'

const state = crypto.randomUUID()
sessionStorage.setItem('login_state', state)
window.location.href = loginUrl(clientId, 'https://example.com/reviews/callback', 'osm', undefined, state)

For bluesky, pass the person’s handle or DID as the sixth argument when you have it; it chooses their server, and the login then checks that the account they authorize is that one. Without it the login goes to bsky.social, which hosts most accounts:

window.location.href = loginUrl(clientId, callback, 'bluesky', undefined, state, 'name.example.com')

For passkey, the signer sends the browser to a page of its own, where the person signs in with a passkey they already have or creates an account with a new one. The page runs the WebAuthn ceremony on the signer’s origin, because a browser signs only for the site the passkey was created on, so the same passkey logs in from every app that uses the signer:

window.location.href = loginUrl(clientId, callback, 'passkey', undefined, state)

The page shows two buttons of equal size, one to log in and one to create an account. A sign-up button of your app can open the page on account creation, with login still offered:

window.location.href = loginUrl(clientId, callback, 'passkey', undefined, state, undefined, true)

The user authorizes your app at the provider, or completes the passkey ceremony, and lands on your callback URL with the session in the URL fragment:

https://example.com/reviews/callback#session_token=<token>&reviewer_id=<uuid>&did=<did>&state=<state>

The did is the person’s identity, the same on every login. The fragment stays in the browser and never reaches your server or its logs. If the user refuses, or the login fails, the fragment carries error and error_description instead, with the same state.

On the callback page, check the state, read the session, keep the token, and remove it from the address bar. The state check matters: without it a link could log the browser in to someone else’s account, so that later reviews are signed as that person.

import { parseCallback } from 'mangrove-reviews/signer'

const session = parseCallback(window.location.href)
if (session.state !== sessionStorage.getItem('login_state')) {
  showError('This login was not started here')
} else if (session.sessionToken) {
  sessionStorage.setItem('signer_token', session.sessionToken)
  sessionStorage.setItem('reviewer_id', session.reviewerId)
  sessionStorage.setItem('did', session.did)
} else {
  const params = new URLSearchParams(window.location.hash.slice(1))
  showError(params.get('error_description'))
}
sessionStorage.removeItem('login_state')
history.replaceState(null, '', window.location.pathname)

A session expires 30 days after its last use, and 180 days after login at the latest. Every call that presents the session moves the first limit, so an app in regular use keeps its person logged in. After expiry, signing rejects with an ApiError whose status is 401, and the app sends the user through login again. Every refused call rejects the same way, with the server’s reason in body.

getAccount(sessionToken) returns the account to its owner: the key and identity, and the login behind them: provider is the provider the person first logged in with, and account_name is their display name there as of the last login (the OpenStreetMap user name, the Bluesky handle), so the app can say which account is connected. The name is the provider’s word and not part of any review; a name that other people see must go into the review metadata, as nickname does, or become a verified alias of the identity, which the identity guide explains. getPublicKey(reviewerId) is the public view, the key and the identity alone.

Use the app’s own OpenStreetMap login

An app that logs people in to OpenStreetMap itself exchanges that login for a session, so the person logs in once. To set it up:

  1. Enable the openid scope in the app’s registration at openstreetmap.org and request it in the app’s login, next to its other scopes. OpenStreetMap asks existing users for consent once more, since the scope is new.
  2. Give the signer operator the app’s OpenStreetMap client id along with the request for a signer client id, as in Register your app. The signer accepts an ID token only when OpenStreetMap issued it to that client.
  3. After the login, take id_token from OpenStreetMap’s token response and exchange it at once. The token expires 120 seconds after the login.
import { exchangeOsmIdToken } from 'mangrove-reviews/signer'

// tokens is the response of the app's own OpenStreetMap token request.
const { sessionToken, reviewerId, did } = await exchangeOsmIdToken(clientId, tokens.id_token)

The session is the one a redirect login with osm gives, for the same reviewer, and the person sees no signer page. The call rejects with 401 for a token that fails a check, such as one OpenStreetMap issued to another app, with 400 for an app without a registered OpenStreetMap client, and with 404 for an unknown client id. A first login through the exchange offers no MapComplete key choice, so an app that finds a key in the preferences sends the person to the MapComplete page.

Sign and submit a review

Build the review payload as the Mangrove Review Standard describes. One call signs it and submits it:

import { signAndSubmitReview } from 'mangrove-reviews/signer'

const { jwt, signature, public_key } = await signAndSubmitReview(
  sessionStorage.getItem('signer_token'),
  {
    sub: 'https://example.com',
    rating: 80,
    opinion: 'Friendly staff, quick service.',
    metadata: { nickname: 'Ada' }
  }
)

The signer sets the issue time itself and signs only the fields of a review payload, so a payload that does not parse as a review is refused with 400 and the message says which field is wrong. The signature identifies the review from now on. The client has helpers for what comes after:

import { editReview, deleteReview, rateReview, reportAbuseReview } from 'mangrove-reviews/signer'

await editReview(token, signature, { rating: 90, opinion: 'Even better on a second visit.' })
await rateReview(token, otherSignature, 100, 'Helpful review')
await reportAbuseReview(token, otherSignature, 'Spam')
await deleteReview(token, signature)

A review can carry photos. Attach Photos to Reviews shows how the app uploads them before the review.

Fill the review from the profile

A profile holds the details a person wants on their reviews: nickname, given name, family name, gender and year of birth. The person saves it once, on mangrove.reviews or in any app, and every app fills new reviews from it. getProfile returns the profile of the identity from the callback, or null before the person saves one:

import { getProfile } from 'mangrove-reviews'

const profile = await getProfile(did)
const { birthdate, ...metadata } = profile ? profile.details : {}
// A review carries the age, and the profile carries the year of birth.
if (birthdate) metadata.age = new Date().getFullYear() - Number(birthdate)

Pass metadata with the review, and let the person change any detail before posting. An app may also save details as the profile with publishProfile. The profile is public, the year of birth included, so the app tells the person before it saves:

import { publishProfile } from 'mangrove-reviews/signer'

await publishProfile(token, did, { nickname: 'Ada', birthdate: '1990' })

A profile replaces the one before it, so a detail left out or empty is cleared. The standard defines the profile.

Show the reviewer

The did from the callback names the reviewer in the dataset, and the public_key in the signing response is the key the signer uses for them. Pass the DID as the did filter to list everything the person has written, from any app and any key bound to the identity:

import { getReviews, getIssuer } from 'mangrove-reviews'

const mine = await getReviews({ did })
const profile = await getIssuer(did)

Reviews in the answer carry did next to kid, so a list of reviews by many people can mark the ones with an identity and link each to its profile.

The account page

Every app has the same rights at the signer. An app session signs reviews, reads the account with getAccount and logs out. The person changes their account on the signer’s account page, https://signer.mangrove.reviews/manage, where they log in again. The page covers these changes:

  • listing, adding and removing passkeys
  • setting and removing a recovery key
  • adding and removing keys of their own
  • adding and removing aliases
  • using their own Bluesky identity

The page keeps its login in a cookie that only the signer’s own pages can send, so a script that takes an app’s session cannot change the account. An app links to the page with a plain link, built by manageUrl:

import { manageUrl } from 'mangrove-reviews/signer'

const link = manageUrl({ returnTo: 'https://example.com/reviews/callback' })

The page offers the way back when returnTo is a registered redirect URI of an app.

Identity

Every person who logs in gets a did:plc identity whose document lists the signer’s key for them. The identity guide explains what a DID document is and how reviews bind to it. The person manages the identity on the account page.

A recovery key lets the person take the identity away from the signer. The account page generates one in the browser, offers its private half as a download, and places its did:key ahead of the signer’s key among the rotation keys, as the did:plc method allows.

A key of the person’s own can join the document, so reviews signed with it count under the identity. An app that holds the local key the person used before logging in proposes it in the link, and the page lists it once the person confirms. The app then lets the key claim the identity with claimIdentity from mangrove-reviews, and the reviews of both keys show under the DID:

import { manageUrl } from 'mangrove-reviews/signer'
import { claimIdentity, didKeyFromPem, publicToPem } from 'mangrove-reviews'

const pem = await publicToPem(localKeypair.publicKey)
window.location.href = manageUrl({ addKey: didKeyFromPem(pem), returnTo })
// Back from the page:
await claimIdentity(localKeypair, did)

An app whose key sits in the person’s OpenStreetMap preferences links it through the signer’s MapComplete page, described in Link a MapComplete key.

A person who logged in with Bluesky can use their own identity instead of the Mangrove one, so their reviews show under their DID with their handle as verified name. On the account page their server authorizes identity operations and emails them a code, which they enter there. Reviews signed before the change stay under the Mangrove DID.

Publishing copies the identity’s operation log to the PLC directory shared with Bluesky, so AT Protocol software can resolve it. Each operation in the log carries its own signature, so the reviewer server publishes on request from any app, and the request takes an empty body. The person decides, and the app asks:

import { publishIdentity } from 'mangrove-reviews'

const { url } = await publishIdentity(did)

A person who holds a recovery key changes the identity document without the signer, by signing operations with that key and filing them with the reviewer server at PUT /identity/{did}/operations. The account page serves everyone else.

Every person has an identity whether or not they visit the account page, and the DID arrives on every login.

MapComplete keeps its review key in the person’s OpenStreetMap preferences, under mangroveidentity. Every app with read_prefs on the account can copy that key. The signer’s page at https://signer.mangrove.reviews/mapcomplete links the key’s reviews to the person’s identity and can remove the key from the preferences. Any app or plain link may send the person there. The page logs them in with OpenStreetMap, shows how many reviews the key signed and the latest five, and offers three choices:

  • link the reviews
  • link the reviews and remove the key
  • remove the key without linking

Linking lists the key in the identity’s document and has it claim the identity, so its reviews show under the DID. Removing deletes every preference whose name starts with mangroveidentity. After a link, the reviews the key signed before the removal stay under the identity.

An app’s own OpenStreetMap login offers the same choice when it creates an account and the preferences hold a key. The third choice there keeps a separate identity, and the key and its reviews stay as they are. The app’s callback then carries mapcomplete in the fragment, with the value linked, revoked (linked and removed), separate or failed, and parseCallback returns it:

const { sessionToken, mapcomplete } = parseCallback(window.location.href)
if (mapcomplete === 'failed') showNotice('The MapComplete key could not be linked')

A failed choice still completes the login.

Passkeys of an account

A person can add a passkey to their account on the account page, whichever way they logged in, and see and remove the passkeys they have there. The page lists each passkey with the name given when it was made, its creation and its last use. The only login of an account stays, so an account made with a passkey keeps at least one.

Log out

Revoke the session and forget the token:

import { revokeSession } from 'mangrove-reviews/signer'

await revokeSession(sessionStorage.getItem('signer_token'))
sessionStorage.removeItem('signer_token')

The signer is part of the Mangrove repository, under the Apache License 2.0. Its endpoints, request bodies and status codes are in its OpenAPI document.