Skip to content

At a glance

Audience
App developers
Type
How-to
Before you start
An AT Protocol OAuth session in your app
Status
current

At a glance

Audience
App developers
Type
How-to
Before you start
An AT Protocol OAuth session in your app
Status
current

Getting Started ​

This page takes an app from sign-in to its first private post. You find the user's EnrollmentA user's membership of a Stratos service, established through OAuth. Stratos stores the user's boundaries and publishes an enrollment record to the user's PDS. Glossary , learn their

CustodyWhich party keeps a user's private records. stratos custody: Stratos hosts the repository and signs with a per-user key. pds custody: the user's own spaces-capable PDS hosts the repository and signs with the account key. Glossary , and send each new post to oneBoundaryA named group whose members can read each other's posts. Its full identifier is {serviceDid}/{name}, for example did:web:stratos.example.com/engineering. A record belongs to exactly one boundary. Glossary .

New to the ideas? Read What is Stratos? Explained simply first.

What you are integrating ​

A private post is a zone.stratos.feed.post record in exactly one boundary. The Stratos service is the space authority: it decides who belongs to each boundary. The terms are defined in the Glossary.

The packages ​

@northskysocial/stratos-client has the framework-neutral building blocks:

ModuleWhat it provides
discoverygetEnrollmentByServiceDid, discoverEnrollments, parseEnrollmentRecord
routingresolveRepositoryTarget, createServiceFetchHandler, findEnrollmentByService, resolveServiceUrl, serviceDIDToRkey
verificationverifyRecordCid, verifyStratosRecord, verifyCidIntegrity, resolveServiceSigningKey, resolveUserSigningKey
attestationverifyEnrollmentAttestation
scopesbuildStratosScopes, buildCollectionScope, buildRpcScope, STRATOS_SCOPES
bash
npm install @northskysocial/stratos-client

@northskysocial/stratos-browser adds browser OAuth and DPoP helpers. The demo webapp uses it. See Browser helpers.

Authentication in one paragraph ​

Stratos accepts the user's AT Protocol OAuth session. Every authenticated user request carries two headers: Authorization: DPoP <access_token> and DPoP: <proof>. Stratos does not accept Authorization: Bearer from a user. Your OAuth library builds both headers when you pass it the absolute Stratos URL. See DPoP-aware transport.

The walk ​

1. Discover the enrollment ​

The enrollment record lives on the user's PDS. Its record key is the Stratos service DID, so one getRecord call finds it:

typescript
import { getEnrollmentByServiceDid } from '@northskysocial/stratos-client'

// Both values come from your app configuration.
const STRATOS_URL = 'https://stratos.example.com'
const STRATOS_DID = 'did:web:stratos.example.com'

async function findEnrollment(userDid: string, sessionPdsUrl: string) {
  return getEnrollmentByServiceDid(userDid, sessionPdsUrl, STRATOS_DID)
}

A null result means the user is not enrolled. Send them through enrollment.

STRATOS_URL and STRATOS_DID are trusted values from your configuration. The record's own service and repoHost fields are hints. Do not route credentials by them.

2. Read custody and resolve the target ​

The enrollment says who keeps the user's records. resolveRepositoryTarget turns that into a host you can trust:

typescript
import { resolveRepositoryTarget } from '@northskysocial/stratos-client'
import type {
  RepositoryTarget,
  StratosEnrollment,
} from '@northskysocial/stratos-client'

const STRATOS_URL = 'https://stratos.example.com'

function resolveTarget(
  enrollment: StratosEnrollment | null,
  sessionPdsUrl: string,
): RepositoryTarget {
  return resolveRepositoryTarget(enrollment, {
    authorityServiceUrl: STRATOS_URL,
    sessionPdsUrl,
  })
}

The result has a kind:

  • stratos: Stratos hosts the repo. Use com.atproto.repo.* on target.url.
  • pds: the user's PDS hosts the repo. Use com.atproto.space.* there.
  • unresolved: stop. target.reason names the cause.

Custody and Routing lists every reason and the rules for trusted hosts.

3. Write the post ​

Branch on target.kind. The Stratos branch writes a record in a Stratos repository, addressed by an at:// URI. The PDS branch writes into a space.

typescript
import { Agent } from '@atproto/api'
import type { OAuthSession } from '@atproto/oauth-client-browser'
import type { RepositoryTarget } from '@northskysocial/stratos-client'

function createRoutedAgent(session: OAuthSession, targetUrl: string): Agent {
  return new Agent((url: string, init: RequestInit) => {
    const fullUrl = new URL(url, targetUrl)
    return session.fetchHandler(fullUrl.href, init)
  })
}

async function createPrivatePost(
  session: OAuthSession,
  target: RepositoryTarget,
  boundary: string,
  spaceUri: string,
  text: string,
): Promise<void> {
  const createdAt = new Date().toISOString()

  if (target.kind === 'stratos') {
    const agent = createRoutedAgent(session, target.url)
    await agent.com.atproto.repo.createRecord({
      repo: session.sub,
      collection: 'zone.stratos.feed.post',
      record: {
        $type: 'zone.stratos.feed.post',
        text,
        boundary: {
          $type: 'zone.stratos.boundary.defs#Domains',
          values: [
            { $type: 'zone.stratos.boundary.defs#Domain', value: boundary },
          ],
        },
        createdAt,
      },
    })
    return
  }

  if (target.kind === 'pds') {
    const response = await session.fetchHandler(
      '/xrpc/com.atproto.space.createRecord',
      {
        method: 'POST',
        headers: { 'content-type': 'application/json' },
        body: JSON.stringify({
          space: spaceUri,
          repo: session.sub,
          collection: 'zone.stratos.feed.post',
          validate: false,
          record: { $type: 'zone.stratos.feed.post', text, createdAt },
        }),
      },
    )
    if (!response.ok) {
      throw new Error(`PDS write failed (${response.status})`)
    }
    return
  }

  throw new Error(`Cannot route the write: ${target.reason}`)
}

boundary is one of the user's boundaries, such as did:web:stratos.example.com/general. spaceUri is the same boundary as a space: at:space/did:web:stratos.example.com/zone.stratos.space.feed/general.

Three rules apply to the Stratos branch:

  • values holds exactly one boundary. Zero or two fail with InvalidDomainCount.
  • The boundary must belong to this service and to the user.
  • Stratos answers PdsCustodyWriteForbidden if the user has pds custody.

The PDS branch needs the space scope on the session. See Space scope.

Common mistake

new Agent(session) followed by agent.serviceUrl = new URL(target.url) still sends requests to the session's PDS. Pass the absolute target URL to the session's fetch handler, as createRoutedAgent does.

4. Read ​

For a single Stratos-hosted record, call com.atproto.repo.getRecord on Stratos. For a feed, call the feed generator. It serves posts from both custody classes. See Reading Records.

Which operations go where ​

OperationHostAuth
com.atproto.repo.createRecordStratos, stratos custodyDPoP
com.atproto.repo.deleteRecordStratos, stratos custodyDPoP
com.atproto.repo.applyWritesStratos, stratos custodyDPoP
com.atproto.repo.uploadBlobStratos, stratos custodyDPoP
com.atproto.repo.getRecord, listRecordsStratos, stratos custodyOptional DPoP
com.atproto.repo.describeRepoStratos, stratos custodyNone
com.atproto.sync.getBlobStratos, stratos custodyOptional DPoP
zone.stratos.sync.getRepoStratos, stratos custodyDPoP, repo owner only
zone.stratos.enrollment.statusStratosOptional DPoP
com.atproto.space.createRecord, deleteRecordUser's PDS, pds custodyThe PDS session and space scope
zone.stratos.feedgen.getFeedFeed generatorService auth JWT

Stratos does not serve com.atproto.repo.putRecord, com.atproto.sync.getRecord, or zone.stratos.repo.importRepo. The API methods has the full list.

DPoP-aware transport ​

A DPoP proof names the URL it was made for, in its htu claim. The OAuth client derives htu from the request URL. So one rule covers everything: pass an absolute URL on the target origin to the session's fetch handler. The proof then matches the Stratos origin instead of the PDS.

createServiceFetchHandler does this for @atcute/client:

typescript
import { Client } from '@atcute/client'
import { createServiceFetchHandler } from '@northskysocial/stratos-client'
import type { FetchHandler } from '@northskysocial/stratos-client'

function createStratosClient(
  authenticatedHandler: FetchHandler,
  stratosUrl: string,
): Client {
  return new Client({
    handler: createServiceFetchHandler(authenticatedHandler, stratosUrl),
  })
}

authenticatedHandler is any function (pathname, init) => Promise<Response> that attaches the access token and the proof. The returned object resolves each pathname against stratosUrl. A third argument, { headers }, sets extra headers on every request.

Use this transport for stratos custody only.

Adoption path ​

Add Stratos support in steps:

Step 1: Read ​

  1. Discover the enrollment when a session starts. Cache it for the session.
  2. Resolve the repository target.
  3. Show a feed from the feed generator.
  4. Render an empty state for a stratos-custody repo that has no records yet.

Step 2: Write ​

  1. Add the Stratos scopes to your OAuth client metadata. See OAuth Scopes.
  2. Branch the composer on target.kind.
  3. Let the user pick one boundary per post.

Step 3: Verify ​

  1. Verify the enrollment attestation.
  2. Verify record CIDs with verifyRecordCid.
  3. Show the verification level honestly. See Attestation Verification.

Step 4: Rich features ​

  1. Boundary chips and filters.
  2. Images. See Creating Records.
  3. Feed attachments. See Private Feed Attachments.

social-app integration mapping ​

For a React Native app shaped like Bluesky's social-app:

State layer ​

Conceptsocial-app locationPattern
Enrollment statesrc/state/stratos.tsx (new)React Context with StratosEnrollment | null | undefined
Repository targetsrc/state/stratos.tsx (new)Derived from the enrollment with resolveRepositoryTarget
Discovery triggersrc/state/session/index.tsxCall getEnrollmentByServiceDid in resumeSession / login flows
Cleanup on logoutsrc/state/session/index.tsxReset enrollment state in the logout handler

View integration ​

ViewIntegration pointWhat changes
Feedsrc/state/queries/post-feed.tsAdd a feed generator query for private posts
Settingssrc/screens/Settings/Enrollment status and boundaries
Record creationPost composerSelect repo or space createRecord by custody

Next steps ​