Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phone verification on entryway #2055

Merged
merged 25 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-and-push-pds-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- main
- multi-pds-auth
env:
REGISTRY: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_REGISTRY }}
USERNAME: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_USERNAME }}
Expand Down
2 changes: 2 additions & 0 deletions lexicons/com/atproto/server/createAccount.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"handle": { "type": "string", "format": "handle" },
"did": { "type": "string", "format": "did" },
"inviteCode": { "type": "string" },
"verificationCode": { "type": "string" },
"verificationPhone": { "type": "string" },
"password": { "type": "string" },
"recoveryKey": { "type": "string" },
"plcOp": { "type": "unknown" }
Expand Down
1 change: 1 addition & 0 deletions lexicons/com/atproto/server/describeServer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"required": ["availableUserDomains"],
"properties": {
"inviteCodeRequired": { "type": "boolean" },
"phoneVerificationRequired": { "type": "boolean" },
"availableUserDomains": {
"type": "array",
"items": { "type": "string" }
Expand Down
20 changes: 20 additions & 0 deletions lexicons/com/atproto/temp/requestPhoneVerification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"lexicon": 1,
"id": "com.atproto.temp.requestPhoneVerification",
"defs": {
"main": {
"type": "procedure",
"description": "Request a verification code to be sent to the supplied phone number",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["phoneNumber"],
"properties": {
"phoneNumber": { "type": "string" }
}
}
}
}
}
}
7 changes: 1 addition & 6 deletions packages/api/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ export class AtpAgent {
opts: AtpAgentCreateAccountOpts,
): Promise<ComAtprotoServerCreateAccount.Response> {
try {
const res = await this.api.com.atproto.server.createAccount({
handle: opts.handle,
password: opts.password,
email: opts.email,
inviteCode: opts.inviteCode,
})
const res = await this.api.com.atproto.server.createAccount(opts)
this.session = {
accessJwt: res.data.accessJwt,
refreshJwt: res.data.refreshJwt,
Expand Down
13 changes: 13 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscrib
import * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
import * as ComAtprotoTempImportRepo from './types/com/atproto/temp/importRepo'
import * as ComAtprotoTempPushBlob from './types/com/atproto/temp/pushBlob'
import * as ComAtprotoTempRequestPhoneVerification from './types/com/atproto/temp/requestPhoneVerification'
import * as ComAtprotoTempTransferAccount from './types/com/atproto/temp/transferAccount'
import * as AppBskyActorDefs from './types/app/bsky/actor/defs'
import * as AppBskyActorGetPreferences from './types/app/bsky/actor/getPreferences'
Expand Down Expand Up @@ -229,6 +230,7 @@ export * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscrib
export * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
export * as ComAtprotoTempImportRepo from './types/com/atproto/temp/importRepo'
export * as ComAtprotoTempPushBlob from './types/com/atproto/temp/pushBlob'
export * as ComAtprotoTempRequestPhoneVerification from './types/com/atproto/temp/requestPhoneVerification'
export * as ComAtprotoTempTransferAccount from './types/com/atproto/temp/transferAccount'
export * as AppBskyActorDefs from './types/app/bsky/actor/defs'
export * as AppBskyActorGetPreferences from './types/app/bsky/actor/getPreferences'
Expand Down Expand Up @@ -1238,6 +1240,17 @@ export class TempNS {
})
}

requestPhoneVerification(
data?: ComAtprotoTempRequestPhoneVerification.InputSchema,
opts?: ComAtprotoTempRequestPhoneVerification.CallOptions,
): Promise<ComAtprotoTempRequestPhoneVerification.Response> {
return this._service.xrpc
.call('com.atproto.temp.requestPhoneVerification', opts?.qp, data, opts)
.catch((e) => {
throw ComAtprotoTempRequestPhoneVerification.toKnownErr(e)
})
}

transferAccount(
data?: ComAtprotoTempTransferAccount.InputSchema,
opts?: ComAtprotoTempTransferAccount.CallOptions,
Expand Down
34 changes: 34 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,12 @@ export const schemaDict = {
inviteCode: {
type: 'string',
},
verificationCode: {
type: 'string',
},
verificationPhone: {
type: 'string',
},
password: {
type: 'string',
},
Expand Down Expand Up @@ -3259,6 +3265,9 @@ export const schemaDict = {
inviteCodeRequired: {
type: 'boolean',
},
phoneVerificationRequired: {
type: 'boolean',
},
availableUserDomains: {
type: 'array',
items: {
Expand Down Expand Up @@ -4331,6 +4340,29 @@ export const schemaDict = {
},
},
},
ComAtprotoTempRequestPhoneVerification: {
lexicon: 1,
id: 'com.atproto.temp.requestPhoneVerification',
defs: {
main: {
type: 'procedure',
description:
'Request a verification code to be sent to the supplied phone number',
input: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['phoneNumber'],
properties: {
phoneNumber: {
type: 'string',
},
},
},
},
},
},
},
ComAtprotoTempTransferAccount: {
lexicon: 1,
id: 'com.atproto.temp.transferAccount',
Expand Down Expand Up @@ -8239,6 +8271,8 @@ export const ids = {
ComAtprotoTempFetchLabels: 'com.atproto.temp.fetchLabels',
ComAtprotoTempImportRepo: 'com.atproto.temp.importRepo',
ComAtprotoTempPushBlob: 'com.atproto.temp.pushBlob',
ComAtprotoTempRequestPhoneVerification:
'com.atproto.temp.requestPhoneVerification',
ComAtprotoTempTransferAccount: 'com.atproto.temp.transferAccount',
AppBskyActorDefs: 'app.bsky.actor.defs',
AppBskyActorGetPreferences: 'app.bsky.actor.getPreferences',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface InputSchema {
handle: string
did?: string
inviteCode?: string
verificationCode?: string
verificationPhone?: string
password?: string
recoveryKey?: string
plcOp?: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type InputSchema = undefined

export interface OutputSchema {
inviteCodeRequired?: boolean
phoneVerificationRequired?: boolean
availableUserDomains: string[]
links?: Links
[k: string]: unknown
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { Headers, XRPCError } from '@atproto/xrpc'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'
import { CID } from 'multiformats/cid'

export interface QueryParams {}

export interface InputSchema {
phoneNumber: string
[k: string]: unknown
}

export interface CallOptions {
headers?: Headers
qp?: QueryParams
encoding: 'application/json'
}

export interface Response {
success: boolean
headers: Headers
}

export function toKnownErr(e: any) {
if (e instanceof XRPCError) {
}
return e
}
9 changes: 3 additions & 6 deletions packages/api/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ComAtprotoServerCreateAccount } from './client'
import { LabelPreference } from './moderation/types'

/**
Expand Down Expand Up @@ -36,12 +37,8 @@ export interface AtpAgentOpts {
/**
* AtpAgent createAccount() opts
*/
export interface AtpAgentCreateAccountOpts {
email: string
password: string
handle: string
inviteCode?: string
}
export type AtpAgentCreateAccountOpts =
ComAtprotoServerCreateAccount.InputSchema

/**
* AtpAgent login() opts
Expand Down
12 changes: 12 additions & 0 deletions packages/bsky/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscrib
import * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
import * as ComAtprotoTempImportRepo from './types/com/atproto/temp/importRepo'
import * as ComAtprotoTempPushBlob from './types/com/atproto/temp/pushBlob'
import * as ComAtprotoTempRequestPhoneVerification from './types/com/atproto/temp/requestPhoneVerification'
import * as ComAtprotoTempTransferAccount from './types/com/atproto/temp/transferAccount'
import * as AppBskyActorGetPreferences from './types/app/bsky/actor/getPreferences'
import * as AppBskyActorGetProfile from './types/app/bsky/actor/getProfile'
Expand Down Expand Up @@ -1053,6 +1054,17 @@ export class TempNS {
return this._server.xrpc.method(nsid, cfg)
}

requestPhoneVerification<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
ComAtprotoTempRequestPhoneVerification.Handler<ExtractAuth<AV>>,
ComAtprotoTempRequestPhoneVerification.HandlerReqCtx<ExtractAuth<AV>>
>,
) {
const nsid = 'com.atproto.temp.requestPhoneVerification' // @ts-ignore
return this._server.xrpc.method(nsid, cfg)
}

transferAccount<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
Expand Down
34 changes: 34 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,12 @@ export const schemaDict = {
inviteCode: {
type: 'string',
},
verificationCode: {
type: 'string',
},
verificationPhone: {
type: 'string',
},
password: {
type: 'string',
},
Expand Down Expand Up @@ -3259,6 +3265,9 @@ export const schemaDict = {
inviteCodeRequired: {
type: 'boolean',
},
phoneVerificationRequired: {
type: 'boolean',
},
availableUserDomains: {
type: 'array',
items: {
Expand Down Expand Up @@ -4331,6 +4340,29 @@ export const schemaDict = {
},
},
},
ComAtprotoTempRequestPhoneVerification: {
lexicon: 1,
id: 'com.atproto.temp.requestPhoneVerification',
defs: {
main: {
type: 'procedure',
description:
'Request a verification code to be sent to the supplied phone number',
input: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['phoneNumber'],
properties: {
phoneNumber: {
type: 'string',
},
},
},
},
},
},
},
ComAtprotoTempTransferAccount: {
lexicon: 1,
id: 'com.atproto.temp.transferAccount',
Expand Down Expand Up @@ -8239,6 +8271,8 @@ export const ids = {
ComAtprotoTempFetchLabels: 'com.atproto.temp.fetchLabels',
ComAtprotoTempImportRepo: 'com.atproto.temp.importRepo',
ComAtprotoTempPushBlob: 'com.atproto.temp.pushBlob',
ComAtprotoTempRequestPhoneVerification:
'com.atproto.temp.requestPhoneVerification',
ComAtprotoTempTransferAccount: 'com.atproto.temp.transferAccount',
AppBskyActorDefs: 'app.bsky.actor.defs',
AppBskyActorGetPreferences: 'app.bsky.actor.getPreferences',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface InputSchema {
handle: string
did?: string
inviteCode?: string
verificationCode?: string
verificationPhone?: string
password?: string
recoveryKey?: string
plcOp?: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type InputSchema = undefined

export interface OutputSchema {
inviteCodeRequired?: boolean
phoneVerificationRequired?: boolean
availableUserDomains: string[]
links?: Links
[k: string]: unknown
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import express from 'express'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'
import { HandlerAuth } from '@atproto/xrpc-server'

export interface QueryParams {}

export interface InputSchema {
phoneNumber: string
[k: string]: unknown
}

export interface HandlerInput {
encoding: 'application/json'
body: InputSchema
}

export interface HandlerError {
status: number
message?: string
}

export type HandlerOutput = HandlerError | void
export type HandlerReqCtx<HA extends HandlerAuth = never> = {
auth: HA
params: QueryParams
input: HandlerInput
req: express.Request
res: express.Response
}
export type Handler<HA extends HandlerAuth = never> = (
ctx: HandlerReqCtx<HA>,
) => Promise<HandlerOutput> | HandlerOutput
7 changes: 6 additions & 1 deletion packages/dev-env/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './env'
import { generateMockSetup } from './mock'
import { TestNetwork } from './network'
import { mockMailer } from './util'
import { mockMailer, mockTwilio } from './util'

const run = async () => {
console.log(`
Expand All @@ -20,13 +20,18 @@ const run = async () => {
hostname: 'localhost',
dbPostgresSchema: 'pds',
enableDidDocWithSession: true,
phoneVerificationRequired: true,
twilioAccountSid: 'ACXXXXXXX',
twilioAuthToken: 'AUTH',
twilioServiceSid: 'VAXXXXXXXX',
},
bsky: {
dbPostgresSchema: 'bsky',
},
plc: { port: 2582 },
})
mockMailer(network.pds)
mockTwilio(network.pds)
await generateMockSetup(network)

console.log(
Expand Down
Loading
Loading