UNPKG

@atproto/oauth-client

Version:

OAuth client for ATPROTO PDS. This package serves as common base for environment-specific implementations (NodeJS, Browser, React-Native).

23 lines (18 loc) 840 B
import { atprotoDidSchema } from '@atproto/did' import { oauthTokenResponseSchema } from '@atproto/oauth-types' import { z, TypeOf } from 'zod' import { includesSpaceSeparatedValue, SpaceSeparatedValue } from './util' export type AtprotoScope = SpaceSeparatedValue<'atproto'> export const isAtprotoScope = (input: string): input is AtprotoScope => includesSpaceSeparatedValue(input, 'atproto') export const atprotoScopeSchema = z .string() .refine(isAtprotoScope, 'The "atproto" scope is required') export const atprotoTokenResponseSchema = oauthTokenResponseSchema.extend({ token_type: z.literal('DPoP'), sub: atprotoDidSchema, scope: atprotoScopeSchema, // OpenID is not compatible with atproto identities id_token: z.never().optional(), }) export type AtprotoTokenResponse = TypeOf<typeof atprotoTokenResponseSchema>