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:
| Module | What it provides |
|---|---|
| discovery | getEnrollmentByServiceDid, discoverEnrollments, parseEnrollmentRecord |
| routing | resolveRepositoryTarget, createServiceFetchHandler, findEnrollmentByService, resolveServiceUrl, serviceDIDToRkey |
| verification | verifyRecordCid, verifyStratosRecord, verifyCidIntegrity, resolveServiceSigningKey, resolveUserSigningKey |
| attestation | verifyEnrollmentAttestation |
| scopes | buildStratosScopes, buildCollectionScope, buildRpcScope, STRATOS_SCOPES |
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:
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:
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. Usecom.atproto.repo.*ontarget.url.pds: the user's PDS hosts the repo. Usecom.atproto.space.*there.unresolved: stop.target.reasonnames 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.
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:
valuesholds exactly one boundary. Zero or two fail withInvalidDomainCount.- The boundary must belong to this service and to the user.
- Stratos answers
PdsCustodyWriteForbiddenif the user haspdscustody.
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
| Operation | Host | Auth |
|---|---|---|
com.atproto.repo.createRecord | Stratos, stratos custody | DPoP |
com.atproto.repo.deleteRecord | Stratos, stratos custody | DPoP |
com.atproto.repo.applyWrites | Stratos, stratos custody | DPoP |
com.atproto.repo.uploadBlob | Stratos, stratos custody | DPoP |
com.atproto.repo.getRecord, listRecords | Stratos, stratos custody | Optional DPoP |
com.atproto.repo.describeRepo | Stratos, stratos custody | None |
com.atproto.sync.getBlob | Stratos, stratos custody | Optional DPoP |
zone.stratos.sync.getRepo | Stratos, stratos custody | DPoP, repo owner only |
zone.stratos.enrollment.status | Stratos | Optional DPoP |
com.atproto.space.createRecord, deleteRecord | User's PDS, pds custody | The PDS session and space scope |
zone.stratos.feedgen.getFeed | Feed generator | Service 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:
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
- Discover the enrollment when a session starts. Cache it for the session.
- Resolve the repository target.
- Show a feed from the feed generator.
- Render an empty state for a
stratos-custody repo that has no records yet.
Step 2: Write
- Add the Stratos scopes to your OAuth client metadata. See OAuth Scopes.
- Branch the composer on
target.kind. - Let the user pick one boundary per post.
Step 3: Verify
- Verify the enrollment attestation.
- Verify record CIDs with
verifyRecordCid. - Show the verification level honestly. See Attestation Verification.
Step 4: Rich features
- Boundary chips and filters.
- Images. See Creating Records.
- Feed attachments. See Private Feed Attachments.
social-app integration mapping
For a React Native app shaped like Bluesky's social-app:
State layer
| Concept | social-app location | Pattern |
|---|---|---|
| Enrollment state | src/state/stratos.tsx (new) | React Context with StratosEnrollment | null | undefined |
| Repository target | src/state/stratos.tsx (new) | Derived from the enrollment with resolveRepositoryTarget |
| Discovery trigger | src/state/session/index.tsx | Call getEnrollmentByServiceDid in resumeSession / login flows |
| Cleanup on logout | src/state/session/index.tsx | Reset enrollment state in the logout handler |
View integration
| View | Integration point | What changes |
|---|---|---|
| Feed | src/state/queries/post-feed.ts | Add a feed generator query for private posts |
| Settings | src/screens/Settings/ | Enrollment status and boundaries |
| Record creation | Post composer | Select repo or space createRecord by custody |
Next steps
- Custody and Routing: the two custody classes, record addresses, and trusted hosts.
- User Enrollment: the enrollment record, the OAuth flow, and scopes.
- Creating Records: posts, replies, and images.
- Reading Records: single records, feeds, and verification.
- Boundaries: visibility rules.
- Attestation Verification: the trust model.