End all sessions
A first-party app ends the user's Tempo ID session, which signs the user out of every app.
Overview
The user's Tempo ID session in the browser signs the user in to every app, as single sign-on. accounts.signOut({ everywhere: true }) ends the app's session and that Tempo ID session.
Tempo ID revokes every app's tokens on it, and the next sign-in asks for the user again. Only a first-party app may do this, since it signs the user out of every app:
| App | Call |
|---|---|
| First-party app, which the Admin API registers | accounts.signOut({ everywhere: true }) |
| App with post-logout redirect URIs | RP-initiated logout |
| Any other app | None. everywhere throws Accounts.EverywhereNotAllowedError |
The demo's client ID is this page's origin, so the instance refuses its sign-out of every app, and the demo signs out of the app only.
Walkthrough
These steps change the sign-out of the web example for a first-party app.
Create the instance
Pass the first-party app's clientId. Tempo ID accepts the logout only from an origin of the app's registration.
import { Accounts } from 'accounts'
export const accounts = Accounts.create({
chain: 'testnet',
clientId: 'example-app',
})Sign the user out of every app
everywhere revokes the app's refresh token, then ends the Tempo ID session with POST /v1/auth/logout.
import { accounts } from './tempo.config.js'
export function SignOut() {
async function signOut() {
await accounts.signOut({ everywhere: true })
}
return (
<button onClick={signOut} type="button">
Sign out of every app
</button>
)
}import { Accounts } from 'accounts'
export const accounts = Accounts.create({
chain: 'testnet',
clientId: 'example-app',
})A Tempo ID session of the user in another browser stays.
Handle the refusal
From any other app, everywhere throws Accounts.EverywhereNotAllowedError before any request. Sign out of the app in its place.
import { Accounts } from 'accounts'
import { accounts } from './tempo.config.js'
export function SignOut() {
async function signOut() {
await accounts.signOut({ everywhere: true })
await accounts.signOut({ everywhere: true }).catch((error: unknown) => {
if (!(error instanceof Accounts.EverywhereNotAllowedError)) throw error
return accounts.signOut()
})
}
return (
<button onClick={signOut} type="button">
Sign out of every app
</button>
)
}import { Accounts } from 'accounts'
export const accounts = Accounts.create({
chain: 'testnet',
clientId: 'example-app',
})Use cases
Each use case ends the Tempo ID session where everywhere does not apply, beside signOut.
End the Tempo ID session with the ID token
An app with registered post-logout redirect URIs uses OpenID Connect RP-Initiated Logout, which no action of the package runs. Read the idToken of the session for id_token_hint before signOut empties the session.
import { accounts } from './tempo.config.js'
export function SignOut() {
async function signOut() {
const session = await accounts.session.get()
const idToken = session?.idToken
await accounts.signOut()
if (idToken) {
const url = new URL('/oauth2/end-session', accounts.config.url)
url.searchParams.set('id_token_hint', idToken)
url.searchParams.set('post_logout_redirect_uri', 'https://app.example/')
location.assign(url)
}
}
return (
<button onClick={signOut} type="button">
Sign out of every app
</button>
)
}import { Accounts } from 'accounts'
export const accounts = Accounts.create({
chain: 'testnet',
clientId: 'example-app',
})Tempo ID ends the hinted session if the browser holds it, then redirects to post_logout_redirect_uri. Other apps receive 403 logout_not_permitted. A refresh can omit the ID token, so a session can hold none.
Sign out of a native app
With the redirect plugin and open, a native app signs in through the system browser, whose Tempo ID session everywhere does not end, since the logout sends the app's cookies. After signOut, the next signIn asks Tempo ID for a new login, so Tempo ID shows its sign-in page.
import { Button } from 'react-native'
import { accounts } from './tempo.config.js'
export function SignOut() {
return <Button onPress={() => accounts.signOut()} title="Sign out" />
}import { Accounts } from 'accounts'
import { expo } from 'accounts/expo'
export const accounts = Accounts.create({
chain: 'testnet',
// The client ID of the app's registration.
clientId: 'example-mobile',
plugins: [expo({ redirectUri: 'com.example.app:/callback' })],
})