@atproto/oauth-provider 0.24.2 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/account/account-manager.d.ts +8 -4
- package/dist/account/account-manager.d.ts.map +1 -1
- package/dist/account/account-manager.js +44 -4
- package/dist/account/account-manager.js.map +1 -1
- package/dist/account/account-store.d.ts +9 -6
- package/dist/account/account-store.d.ts.map +1 -1
- package/dist/account/account-store.js +2 -0
- package/dist/account/account-store.js.map +1 -1
- package/dist/account/login-hint.js +1 -1
- package/dist/account/login-hint.js.map +1 -1
- package/dist/account/sign-in-data.d.ts +3 -3
- package/dist/account/sign-in-data.d.ts.map +1 -1
- package/dist/account/sign-in-data.js +2 -1
- package/dist/account/sign-in-data.js.map +1 -1
- package/dist/account/sign-up-input.d.ts +2 -2
- package/dist/account/sign-up-input.js +2 -2
- package/dist/account/sign-up-input.js.map +1 -1
- package/dist/errors/unknown-atproto-account-error.d.ts +13 -0
- package/dist/errors/unknown-atproto-account-error.d.ts.map +1 -0
- package/dist/errors/unknown-atproto-account-error.js +18 -0
- package/dist/errors/unknown-atproto-account-error.js.map +1 -0
- package/dist/oauth-provider.d.ts +5 -2
- package/dist/oauth-provider.d.ts.map +1 -1
- package/dist/oauth-provider.js +20 -4
- package/dist/oauth-provider.js.map +1 -1
- package/dist/router/create-api-middleware.d.ts.map +1 -1
- package/dist/router/create-api-middleware.js +11 -5
- package/dist/router/create-api-middleware.js.map +1 -1
- package/dist/types/email.d.ts +3 -1
- package/dist/types/email.d.ts.map +1 -1
- package/dist/types/email.js +4 -4
- package/dist/types/email.js.map +1 -1
- package/dist/types/indentifier.d.ts +6 -0
- package/dist/types/indentifier.d.ts.map +1 -0
- package/dist/types/indentifier.js +10 -0
- package/dist/types/indentifier.js.map +1 -0
- package/package.json +9 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atproto/oauth-provider
|
|
2
2
|
|
|
3
|
+
## 0.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#5687](https://github.com/bluesky-social/atproto/pull/5687) [`943170b`](https://github.com/bluesky-social/atproto/commit/943170bd390705fbb16920688f8f09ec7078a59b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Support resetting password based on account identifier (in addition to email). When a user attempts to reset password for an Atmosphere account hosted on another service, the user will be notified and show a link to the right service.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`b7dcaee`](https://github.com/bluesky-social/atproto/commit/b7dcaeefbb070b8182dc68b4e6b52114d6786d4e), [`943170b`](https://github.com/bluesky-social/atproto/commit/943170bd390705fbb16920688f8f09ec7078a59b), [`dc47f7b`](https://github.com/bluesky-social/atproto/commit/dc47f7b1a2f91e2d8cf2d1dbbdaa6c443fbfdefb), [`943170b`](https://github.com/bluesky-social/atproto/commit/943170bd390705fbb16920688f8f09ec7078a59b), [`943170b`](https://github.com/bluesky-social/atproto/commit/943170bd390705fbb16920688f8f09ec7078a59b), [`943170b`](https://github.com/bluesky-social/atproto/commit/943170bd390705fbb16920688f8f09ec7078a59b), [`943170b`](https://github.com/bluesky-social/atproto/commit/943170bd390705fbb16920688f8f09ec7078a59b), [`943170b`](https://github.com/bluesky-social/atproto/commit/943170bd390705fbb16920688f8f09ec7078a59b), [`943170b`](https://github.com/bluesky-social/atproto/commit/943170bd390705fbb16920688f8f09ec7078a59b)]:
|
|
12
|
+
- @atproto/oauth-provider-ui@0.11.0
|
|
13
|
+
- @atproto-labs/handle-resolver-node@0.2.15
|
|
14
|
+
- @atproto/oauth-resolver@0.0.1
|
|
15
|
+
- @atproto/oauth-provider-api@0.11.0
|
|
16
|
+
|
|
17
|
+
## 0.24.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`0e60f3f`](https://github.com/bluesky-social/atproto/commit/0e60f3f007cbd9812975489f0da19bf7613da831)]:
|
|
22
|
+
- @atproto-labs/fetch-node@0.4.3
|
|
23
|
+
|
|
3
24
|
## 0.24.2
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Did } from '@atproto/did';
|
|
2
|
+
import type { OAuthResolver } from '@atproto/oauth-resolver';
|
|
2
3
|
import { type OAuthIssuerIdentifier } from '@atproto/oauth-types';
|
|
3
4
|
import type { ClientId } from '../client/client-id.js';
|
|
4
5
|
import type { Client } from '../client/client.js';
|
|
@@ -6,15 +7,17 @@ import type { DeviceId } from '../device/device-id.js';
|
|
|
6
7
|
import { HCaptchaClient, type HcaptchaVerifyResult } from '../lib/hcaptcha.js';
|
|
7
8
|
import type { OAuthHooks, RequestMetadata } from '../oauth-hooks.js';
|
|
8
9
|
import type { Customization } from '../oauth-provider.js';
|
|
9
|
-
import type { Account, AccountStore, AuthorizedClientData, DeleteAccountConfirmInput, DeleteAccountRequestInput, DeviceAccount, DisableEmailAuthFactorInput, EnableEmailAuthFactorInput, HandleString, ResetPasswordConfirmInput, ResetPasswordRequestInput, SignUpData, UpdateEmailConfirmInput, UpdateEmailRequestInput, UpdateHandleData, VerifyEmailConfirmInput, VerifyEmailRequestInput } from './account-store.js';
|
|
10
|
+
import type { Account, AccountStore, AuthorizedClientData, AuthorizedClients, DeleteAccountConfirmInput, DeleteAccountRequestInput, DeviceAccount, DisableEmailAuthFactorInput, EnableEmailAuthFactorInput, HandleString, ResetPasswordConfirmInput, ResetPasswordRequestInput, SignUpData, UpdateEmailConfirmInput, UpdateEmailRequestInput, UpdateHandleData, VerifyEmailConfirmInput, VerifyEmailRequestInput } from './account-store.js';
|
|
10
11
|
import type { SignInData } from './sign-in-data.js';
|
|
11
12
|
import type { SignUpInput } from './sign-up-input.js';
|
|
12
13
|
export declare class AccountManager {
|
|
14
|
+
protected readonly issuer: OAuthIssuerIdentifier;
|
|
13
15
|
protected readonly store: AccountStore;
|
|
14
16
|
protected readonly hooks: OAuthHooks;
|
|
17
|
+
protected readonly oauthResolver: OAuthResolver;
|
|
15
18
|
protected readonly inviteCodeRequired: boolean;
|
|
16
19
|
protected readonly hcaptchaClient?: HCaptchaClient;
|
|
17
|
-
constructor(issuer: OAuthIssuerIdentifier, store: AccountStore, hooks: OAuthHooks, customization: Customization);
|
|
20
|
+
constructor(issuer: OAuthIssuerIdentifier, store: AccountStore, hooks: OAuthHooks, oauthResolver: OAuthResolver, customization: Customization);
|
|
18
21
|
protected processHcaptchaToken(input: SignUpInput, deviceId: DeviceId, deviceMetadata: RequestMetadata): Promise<HcaptchaVerifyResult | undefined>;
|
|
19
22
|
protected enforceInviteCode(input: SignUpInput, _deviceId: DeviceId, _deviceMetadata: RequestMetadata): Promise<string | undefined>;
|
|
20
23
|
protected buildSignupData(input: SignUpInput, deviceId: DeviceId, deviceMetadata: RequestMetadata): Promise<SignUpData>;
|
|
@@ -33,11 +36,12 @@ export declare class AccountManager {
|
|
|
33
36
|
setAuthorizedClient(account: Account, client: Client, data: AuthorizedClientData): Promise<void>;
|
|
34
37
|
getAccount(did: Did): Promise<{
|
|
35
38
|
account: Account;
|
|
36
|
-
authorizedClients:
|
|
37
|
-
}>;
|
|
39
|
+
authorizedClients: AuthorizedClients;
|
|
40
|
+
} | null>;
|
|
38
41
|
listDeviceAccounts(deviceId: DeviceId): Promise<DeviceAccount[]>;
|
|
39
42
|
listAccountDevices(did: Did): Promise<DeviceAccount[]>;
|
|
40
43
|
resetPasswordRequest(deviceId: DeviceId, deviceMetadata: RequestMetadata, input: ResetPasswordRequestInput): Promise<void>;
|
|
44
|
+
private throwUnknownAtmosphereAccount;
|
|
41
45
|
resetPasswordConfirm(deviceId: DeviceId, deviceMetadata: RequestMetadata, input: ResetPasswordConfirmInput): Promise<Account>;
|
|
42
46
|
verifyHandleAvailability(handle: HandleString): Promise<void>;
|
|
43
47
|
updateEmailRequest(deviceId: DeviceId, deviceMetadata: RequestMetadata, input: UpdateEmailRequestInput, account: Account): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-manager.d.ts","sourceRoot":"","sources":["../../src/account/account-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EACL,KAAK,qBAAqB,EAE3B,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"account-manager.d.ts","sourceRoot":"","sources":["../../src/account/account-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EACL,KAAK,qBAAqB,EAE3B,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAItD,OAAO,EAAE,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAG9E,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EAEZ,oBAAoB,EACpB,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,EACzB,aAAa,EACb,2BAA2B,EAC3B,0BAA0B,EAC1B,YAAY,EACZ,yBAAyB,EACzB,yBAAyB,EACzB,UAAU,EACV,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAA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B,cAAc,EAAE,eAAe,EAC/B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,OAAO,CAAC,CAwBlB;IAEY,iBAAiB,CAC5B,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,eAAe,EAC/B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,OAAO,CAAC,CAoBlB;IAEY,oBAAoB,CAC/B,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,eAAe,EAC/B,KAAK,EAAE,yBAAyB,EAChC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,IAAI,CAAC,CAcf;IAEY,oBAAoB,CAC/B,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,eAAe,EAC/B,KAAK,EAAE,yBAAyB,EAChC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf;CACF"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isOAuthClientIdLoopback, } from '@atproto/oauth-types';
|
|
2
|
+
import { isAtIdentifierString } from '@atproto/syntax';
|
|
2
3
|
import { InvalidCredentialsError } from '../errors/invalid-credentials-error.js';
|
|
3
4
|
import { InvalidRequestError } from '../errors/invalid-request-error.js';
|
|
5
|
+
import { UnknownAtprotoAccountError } from '../errors/unknown-atproto-account-error.js';
|
|
4
6
|
import { HCaptchaClient } from '../lib/hcaptcha.js';
|
|
5
7
|
import { callAsync } from '../lib/util/function.js';
|
|
6
8
|
import { constantTime } from '../lib/util/time.js';
|
|
@@ -8,9 +10,11 @@ const TIMING_ATTACK_MITIGATION_DELAY = 400;
|
|
|
8
10
|
const BRUTE_FORCE_MITIGATION_DELAY = 300;
|
|
9
11
|
// @TODO Add rate limit to all the OAuth routes.
|
|
10
12
|
export class AccountManager {
|
|
11
|
-
constructor(issuer, store, hooks, customization) {
|
|
13
|
+
constructor(issuer, store, hooks, oauthResolver, customization) {
|
|
14
|
+
this.issuer = issuer;
|
|
12
15
|
this.store = store;
|
|
13
16
|
this.hooks = hooks;
|
|
17
|
+
this.oauthResolver = oauthResolver;
|
|
14
18
|
this.inviteCodeRequired = customization.inviteCodeRequired !== false;
|
|
15
19
|
this.hcaptchaClient = customization.hcaptcha
|
|
16
20
|
? new HCaptchaClient(new URL(issuer).hostname, customization.hcaptcha)
|
|
@@ -119,9 +123,9 @@ export class AccountManager {
|
|
|
119
123
|
});
|
|
120
124
|
const account = await callAsync(async () => {
|
|
121
125
|
return this.store.authenticateAccount({
|
|
122
|
-
|
|
126
|
+
identifier: data.identifier,
|
|
123
127
|
password: data.password,
|
|
124
|
-
|
|
128
|
+
locale: data.locale,
|
|
125
129
|
emailOtp: data.emailOtp,
|
|
126
130
|
deviceAccounts,
|
|
127
131
|
});
|
|
@@ -218,7 +222,22 @@ export class AccountManager {
|
|
|
218
222
|
.filter((deviceAccount) => deviceAccount.account.did === did);
|
|
219
223
|
}
|
|
220
224
|
async resetPasswordRequest(deviceId, deviceMetadata, input) {
|
|
221
|
-
|
|
225
|
+
// @NOTE We won't be sending reset password emails for non-email identifiers
|
|
226
|
+
// (note that we might want to do that at some point, as other services,
|
|
227
|
+
// e.g. Instagram, allow password reset via username). Supporting this would
|
|
228
|
+
// require adding rate limiting + hCaptcha verification to prevent abuse.
|
|
229
|
+
// Once those defense mechanisms are implemented, the whole "if" here after
|
|
230
|
+
// can be removed as the "if" at the end of this function will handle
|
|
231
|
+
// unknown accounts.
|
|
232
|
+
if (isAtIdentifierString(input.identifier)) {
|
|
233
|
+
// We *DO* however return a specific error message for users identified by
|
|
234
|
+
// an at-identifier that are not hosted on this service.
|
|
235
|
+
const result = await this.store.getAccount(input.identifier);
|
|
236
|
+
if (!result)
|
|
237
|
+
return this.throwUnknownAtmosphereAccount(input.identifier);
|
|
238
|
+
throw new UnknownAtprotoAccountError(input.identifier, undefined, 'An email address is required for password reset');
|
|
239
|
+
}
|
|
240
|
+
const account = await constantTime(TIMING_ATTACK_MITIGATION_DELAY, async () => {
|
|
222
241
|
await this.hooks.onResetPasswordRequest?.call(null, {
|
|
223
242
|
input,
|
|
224
243
|
deviceId,
|
|
@@ -232,7 +251,28 @@ export class AccountManager {
|
|
|
232
251
|
deviceMetadata,
|
|
233
252
|
account,
|
|
234
253
|
});
|
|
254
|
+
return account;
|
|
255
|
+
});
|
|
256
|
+
// @NOTE This is currently a dead branch (because of the "if" above) but
|
|
257
|
+
// will become live once we support password reset via at-identifiers (by
|
|
258
|
+
// removing the "if" at the beginning of this function.
|
|
259
|
+
if (!account && isAtIdentifierString(input.identifier)) {
|
|
260
|
+
return this.throwUnknownAtmosphereAccount(input.identifier);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async throwUnknownAtmosphereAccount(identifier) {
|
|
264
|
+
const { metadata, identityInfo } = await this.oauthResolver
|
|
265
|
+
.resolve(identifier)
|
|
266
|
+
.catch((cause) => {
|
|
267
|
+
throw new UnknownAtprotoAccountError(identifier, undefined, undefined, cause);
|
|
235
268
|
});
|
|
269
|
+
const handle = identityInfo?.handle === 'handle.invalid'
|
|
270
|
+
? undefined
|
|
271
|
+
: identityInfo?.handle;
|
|
272
|
+
// The identity points back at this service (e.g. a taken-down account):
|
|
273
|
+
// there is no other service to direct the user to.
|
|
274
|
+
const issuer = metadata.issuer === this.issuer ? undefined : metadata.issuer;
|
|
275
|
+
throw new UnknownAtprotoAccountError(handle ?? identifier, issuer);
|
|
236
276
|
}
|
|
237
277
|
async resetPasswordConfirm(deviceId, deviceMetadata, input) {
|
|
238
278
|
return constantTime(TIMING_ATTACK_MITIGATION_DELAY, async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-manager.js","sourceRoot":"","sources":["../../src/account/account-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,uBAAuB,GACxB,MAAM,sBAAsB,CAAA;AAI7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,cAAc,EAA6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EAAE,IAAI,CAAC,IAAI,EAAE;YACpD,QAAQ;YACR,cAAc;YACd,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAC/B,QAAkB,EAClB,cAA+B,EAC/B,KAAgC,EAChC,OAAgB;QAEhB,OAAO,YAAY,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAAC,IAAI,EAAE;gBAClD,QAAQ;gBACR,cAAc;gBACd,OAAO;aACR,CAAC,CAAA;YAEF,MAAM,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CACjE,CAAC,GAAG,EAAE,EAAE;gBACN,MAAM,mBAAmB,CAAC,IAAI,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAA;YAChE,CAAC,CACF,CAAA;YAED,MAAM,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,IAAI,CAAC,IAAI,EAAE;gBACpD,QAAQ;gBACR,cAAc;gBACd,OAAO;gBACP,KAAK;aACN,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import type { Did } from '@atproto/did'\nimport {\n type OAuthIssuerIdentifier,\n isOAuthClientIdLoopback,\n} from '@atproto/oauth-types'\nimport type { ClientId } from '../client/client-id.js'\nimport type { Client } from '../client/client.js'\nimport type { DeviceId } from '../device/device-id.js'\nimport { InvalidCredentialsError } from '../errors/invalid-credentials-error.js'\nimport { InvalidRequestError } from '../errors/invalid-request-error.js'\nimport { HCaptchaClient, type HcaptchaVerifyResult } from '../lib/hcaptcha.js'\nimport { callAsync } from '../lib/util/function.js'\nimport { constantTime } from '../lib/util/time.js'\nimport type { OAuthHooks, RequestMetadata } from '../oauth-hooks.js'\nimport type { Customization } from '../oauth-provider.js'\nimport type {\n Account,\n AccountStore,\n AuthorizedClientData,\n DeleteAccountConfirmInput,\n DeleteAccountRequestInput,\n DeviceAccount,\n DisableEmailAuthFactorInput,\n EnableEmailAuthFactorInput,\n HandleString,\n ResetPasswordConfirmInput,\n ResetPasswordRequestInput,\n SignUpData,\n UpdateEmailConfirmInput,\n UpdateEmailRequestInput,\n UpdateHandleData,\n VerifyEmailConfirmInput,\n VerifyEmailRequestInput,\n} from './account-store.js'\nimport type { SignInData } from './sign-in-data.js'\nimport type { SignUpInput } from './sign-up-input.js'\n\nconst TIMING_ATTACK_MITIGATION_DELAY = 400\nconst BRUTE_FORCE_MITIGATION_DELAY = 300\n\n// @TODO Add rate limit to all the OAuth routes.\n\nexport class AccountManager {\n protected readonly inviteCodeRequired: boolean\n protected readonly hcaptchaClient?: HCaptchaClient\n\n constructor(\n issuer: OAuthIssuerIdentifier,\n protected readonly store: AccountStore,\n protected readonly hooks: OAuthHooks,\n customization: Customization,\n ) {\n this.inviteCodeRequired = customization.inviteCodeRequired !== false\n this.hcaptchaClient = customization.hcaptcha\n ? new HCaptchaClient(new URL(issuer).hostname, customization.hcaptcha)\n : undefined\n }\n\n protected async processHcaptchaToken(\n input: SignUpInput,\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n ): Promise<HcaptchaVerifyResult | undefined> {\n if (!this.hcaptchaClient) {\n return undefined\n }\n\n if (!input.hcaptchaToken) {\n throw new InvalidRequestError('hCaptcha token is required')\n }\n\n try {\n const tokens = await this.hcaptchaClient.buildClientTokens(\n deviceMetadata.ipAddress,\n input.handle,\n deviceMetadata.userAgent,\n )\n\n const result = await this.hcaptchaClient.verify(\n 'signup',\n input.hcaptchaToken,\n deviceMetadata.ipAddress,\n tokens,\n )\n\n await this.hooks.onHcaptchaResult?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n tokens,\n result,\n })\n\n this.hcaptchaClient.checkVerifyResult(result, tokens)\n\n return result\n } catch (err) {\n throw InvalidRequestError.from(err, 'hCaptcha verification failed')\n }\n }\n\n protected async enforceInviteCode(\n input: SignUpInput,\n _deviceId: DeviceId,\n _deviceMetadata: RequestMetadata,\n ): Promise<string | undefined> {\n if (!this.inviteCodeRequired) {\n return undefined\n }\n\n if (!input.inviteCode) {\n throw new InvalidRequestError('Invite code is required')\n }\n\n return input.inviteCode\n }\n\n protected async buildSignupData(\n input: SignUpInput,\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n ): Promise<SignUpData> {\n const [hcaptchaResult, inviteCode] = await Promise.all([\n this.processHcaptchaToken(input, deviceId, deviceMetadata),\n this.enforceInviteCode(input, deviceId, deviceMetadata),\n ])\n\n return { ...input, hcaptchaResult, inviteCode }\n }\n\n public async createAccount(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: SignUpInput,\n clientId?: ClientId,\n ): Promise<{ account: Account; remembered: boolean }> {\n return constantTime(BRUTE_FORCE_MITIGATION_DELAY, async () => {\n await callAsync(this.hooks.onSignUpAttempt, {\n input,\n deviceId,\n deviceMetadata,\n clientId,\n })\n\n const data = await this.buildSignupData(input, deviceId, deviceMetadata)\n\n const account = await callAsync(async () => {\n return this.store.createAccount(data)\n }).catch((err) => {\n throw InvalidRequestError.from(err, 'Account creation failed')\n })\n\n // @TODO Any error occurring below this point (server error most likely)\n // will not prevent the account from being created, but it will be\n // reported to the caller. We may want to wrap these errors in a way that\n // allows the UI to detect that a sign-up attempt will fail (\"account\n // already exists\"), and should provide appropriate feedback to the user\n // (eg. show sign-in form?).\n\n const isOAuthFlow = clientId != null\n const remembered = input.remember ?? !isOAuthFlow\n\n if (remembered) {\n await this.upsertDeviceAccount(deviceId, account.did)\n } else {\n // no need to remove the device account since it was never added (the\n // account was just created).\n }\n\n try {\n await callAsync(this.hooks.onSignedUp, {\n data,\n account,\n deviceId,\n deviceMetadata,\n clientId,\n })\n\n return { account, remembered }\n } catch (err) {\n // Delete the device account if an error occurred during the hook\n if (remembered) {\n await this.removeDeviceAccount(deviceId, account.did)\n }\n\n throw InvalidRequestError.from(\n err,\n 'The account was successfully created but something went wrong, try signing-in.',\n )\n }\n })\n }\n\n public async authenticateAccount(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n data: SignInData,\n clientId?: ClientId,\n ): Promise<{ account: Account; remembered: boolean }> {\n return constantTime(TIMING_ATTACK_MITIGATION_DELAY, async () => {\n // @NOTE If the user did not explicitly specify a \"remember\" preference,\n // we will use the existence of previously remembered device accounts to\n // determine the default \"remember\" behavior.\n const deviceAccounts = await this.listDeviceAccounts(deviceId)\n\n await this.hooks.onSignInAttempt?.call(null, {\n data,\n deviceId,\n deviceMetadata,\n deviceAccounts,\n clientId,\n })\n\n const account = await callAsync(async () => {\n return this.store.authenticateAccount({\n locale: data.locale,\n password: data.password,\n username: data.username,\n emailOtp: data.emailOtp,\n deviceAccounts,\n })\n }).catch(async (error) => {\n // Only notify for credential failures (e.g. unknown identifier, wrong\n // password). Server errors and flows that require an additional factor\n // (SecondAuthenticationFactorRequiredError) are not \"failed sign-ins\"\n // and do not trigger the hook.\n\n // Stores that throw the more specific `InvalidCredentialsError`\n // can attach the matched subject identifier to distinguish\n // \"identifier known, password wrong\" from \"identifier unknown\".\n if (error instanceof InvalidRequestError) {\n await this.hooks.onSignInFailed?.call(null, {\n data,\n error,\n did: error instanceof InvalidCredentialsError ? error.did : null,\n deviceId,\n deviceMetadata,\n clientId,\n })\n }\n\n throw error\n })\n\n const remembered =\n // If the user has explicitly specified a \"remember\" preference, use it.\n data.remember ??\n // Fall back to checking if the account was previously remembered.\n deviceAccounts.some((da) => da.account.did === account.did)\n\n if (remembered) {\n await this.upsertDeviceAccount(deviceId, account.did)\n } else {\n // In case the user was already signed in, and signed in again, this\n // time without \"remember me\", let's sign them off of the device.\n await this.removeDeviceAccount(deviceId, account.did)\n }\n\n try {\n await callAsync(this.hooks.onSignedIn, {\n data,\n account,\n remembered,\n deviceId,\n deviceMetadata,\n clientId,\n })\n\n return { account, remembered }\n } catch (err) {\n if (remembered) {\n await this.removeDeviceAccount(deviceId, account.did)\n }\n\n throw err\n }\n }).catch((err) => {\n throw InvalidRequestError.from(\n err,\n 'Unable to sign-in due to an unexpected server error',\n )\n })\n }\n\n public async signOut(deviceId: DeviceId, did: Did) {\n await this.removeDeviceAccount(deviceId, did)\n }\n\n protected async upsertDeviceAccount(\n deviceId: DeviceId,\n did: Did,\n ): Promise<void> {\n await this.store.upsertDeviceAccount(deviceId, did)\n }\n\n protected async removeDeviceAccount(deviceId: DeviceId, did: Did) {\n return this.store.removeDeviceAccount(deviceId, did)\n }\n\n public async getDeviceAccount(\n deviceId: DeviceId,\n did: Did,\n ): Promise<DeviceAccount> {\n const deviceAccount = await this.store.getDeviceAccount(deviceId, did)\n if (!deviceAccount) throw new InvalidRequestError(`Account not found`)\n\n return deviceAccount\n }\n\n public async setAuthorizedClient(\n account: Account,\n client: Client,\n data: AuthorizedClientData,\n ): Promise<void> {\n // \"Loopback\" clients are not distinguishable from one another.\n if (isOAuthClientIdLoopback(client.id)) return\n\n await this.store.setAuthorizedClient(account.did, client.id, data)\n }\n\n public async getAccount(did: Did) {\n return this.store.getAccount(did)\n }\n\n public async listDeviceAccounts(\n deviceId: DeviceId,\n ): Promise<DeviceAccount[]> {\n const deviceAccounts = await this.store.listDeviceAccounts({\n deviceId,\n })\n\n return deviceAccounts // Fool proof\n .filter((deviceAccount) => deviceAccount.deviceId === deviceId)\n }\n\n public async listAccountDevices(did: Did): Promise<DeviceAccount[]> {\n const deviceAccounts = await this.store.listDeviceAccounts({\n did,\n })\n\n return deviceAccounts // Fool proof\n .filter((deviceAccount) => deviceAccount.account.did === did)\n }\n\n public async resetPasswordRequest(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: ResetPasswordRequestInput,\n ) {\n return constantTime(TIMING_ATTACK_MITIGATION_DELAY, async () => {\n await this.hooks.onResetPasswordRequest?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n })\n\n const account = await this.store.resetPasswordRequest(input)\n\n // @NOTE Do not throw here, to prevent user enumeration\n\n await this.hooks.onResetPasswordRequested?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n account,\n })\n })\n }\n\n public async resetPasswordConfirm(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: ResetPasswordConfirmInput,\n ) {\n return constantTime(TIMING_ATTACK_MITIGATION_DELAY, async () => {\n await this.hooks.onResetPasswordConfirm?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n })\n\n const account = await this.store.resetPasswordConfirm(input)\n\n if (!account) {\n throw new InvalidRequestError('Invalid token')\n }\n\n await this.hooks.onResetPasswordConfirmed?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n account,\n })\n\n return account\n })\n }\n\n public async verifyHandleAvailability(handle: HandleString): Promise<void> {\n return constantTime(TIMING_ATTACK_MITIGATION_DELAY, async () => {\n return this.store.verifyHandleAvailability(handle)\n })\n }\n\n public async updateEmailRequest(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: UpdateEmailRequestInput,\n account: Account,\n ): Promise<{ tokenRequired: boolean }> {\n await this.hooks.onChangeEmailRequest?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const { tokenRequired } = await this.store.updateEmailRequest(input)\n\n await this.hooks.onChangeEmailRequested?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n return { tokenRequired: tokenRequired === true }\n }\n\n public async updateEmailConfirm(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: UpdateEmailConfirmInput,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onUpdateEmailConfirm?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const updatedAccount = await this.store.updateEmailConfirm(input)\n\n if (!updatedAccount) {\n throw new InvalidRequestError('Invalid token')\n }\n\n await this.hooks.onUpdateEmailConfirmed?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account: updatedAccount,\n prevAccount: account,\n })\n\n return updatedAccount\n }\n\n public async verifyEmailRequest(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: VerifyEmailRequestInput,\n account: Account,\n ): Promise<void> {\n await this.hooks.onVerifyEmailRequest?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n input,\n })\n\n await this.store.verifyEmailRequest(input)\n\n await this.hooks.onVerifyEmailRequested?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n input,\n })\n }\n\n public async verifyEmailConfirm(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: VerifyEmailConfirmInput,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onVerifyEmailConfirm?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n input,\n })\n\n const updatedAccount = await this.store.verifyEmailConfirm(input)\n\n if (!updatedAccount) {\n throw new InvalidRequestError('Invalid token')\n }\n\n await this.hooks.onVerifyEmailConfirmed?.call(null, {\n deviceId,\n deviceMetadata,\n account: updatedAccount,\n input,\n })\n\n return updatedAccount\n }\n\n public async enableEmailAuthFactor(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: EnableEmailAuthFactorInput,\n account: Account,\n ): Promise<Account> {\n // Already enabled\n if (account.emailAuthFactor) return account\n\n await this.hooks.onEnableEmailAuthFactor?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const updatedAccount = await this.store.enableEmailAuthFactor(input)\n\n if (updatedAccount.emailAuthFactor !== account.emailAuthFactor) {\n await this.hooks.onEnabledEmailAuthFactor?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account: updatedAccount,\n })\n }\n\n return updatedAccount\n }\n\n public async disableEmailAuthFactor(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: DisableEmailAuthFactorInput,\n account: Account,\n ): Promise<Account> {\n // Already disabled\n if (!account.emailAuthFactor) return account\n\n await this.hooks.onDisableEmailAuthFactor?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const updatedAccount = await this.store.disableEmailAuthFactor(input)\n\n if (updatedAccount.emailAuthFactor !== account.emailAuthFactor) {\n await this.hooks.onDisabledEmailAuthFactor?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account: updatedAccount,\n })\n }\n\n return updatedAccount\n }\n\n public async updateHandle(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: UpdateHandleData,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onUpdateHandle?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const updatedAccount = await this.store.updateHandle(input)\n\n await this.hooks.onUpdatedHandle?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account: updatedAccount,\n })\n\n return updatedAccount\n }\n\n public async deactivateAccount(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onDeactivateAccount?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n\n const updatedAccount = await callAsync(() =>\n this.store.deactivateAccount({\n did: account.did,\n // @TODO support setting this from the UI/API\n deleteAfter: undefined,\n }),\n ).catch((err) => {\n throw InvalidRequestError.from(err, 'Account deactivation failed')\n })\n\n await this.hooks.onDeactivatedAccount?.call(null, {\n deviceId,\n deviceMetadata,\n account: updatedAccount,\n })\n\n return updatedAccount\n }\n\n public async reactivateAccount(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onReactivateAccount?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n\n const updatedAccount = await callAsync(() =>\n this.store.reactivateAccount({ did: account.did }),\n ).catch((err) => {\n throw InvalidRequestError.from(err, 'Account reactivation failed')\n })\n\n await this.hooks.onReactivatedAccount?.call(null, {\n deviceId,\n deviceMetadata,\n account: updatedAccount,\n })\n\n return updatedAccount\n }\n\n public async deleteAccountRequest(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: DeleteAccountRequestInput,\n account: Account,\n ): Promise<void> {\n await this.hooks.onDeleteAccountRequest?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n\n await this.store.deleteAccountRequest(input)\n\n await this.hooks.onDeleteAccountRequested?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n }\n\n public async deleteAccountConfirm(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: DeleteAccountConfirmInput,\n account: Account,\n ): Promise<void> {\n return constantTime(BRUTE_FORCE_MITIGATION_DELAY, async () => {\n await this.hooks.onDeleteAccountConfirm?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n\n await callAsync(() => this.store.deleteAccountConfirm(input)).catch(\n (err) => {\n throw InvalidRequestError.from(err, 'Account deletion failed')\n },\n )\n\n await this.hooks.onDeleteAccountConfirmed?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n input,\n })\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"account-manager.js","sourceRoot":"","sources":["../../src/account/account-manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,uBAAuB,GACxB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAItD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,cAAc,EAA6B,MAAM,oBAAoB,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AA2BlD,MAAM,8BAA8B,GAAG,GAAG,CAAA;AAC1C,MAAM,4BAA4B,GAAG,GAAG,CAAA;AAExC,gDAAgD;AAEhD,MAAM,OAAO,cAAc;IAIzB,YACqB,MAA6B,EAC7B,KAAmB,EACnB,KAAiB,EACjB,aAA4B,EAC/C,aAA4B;sBAJT,MAAM;qBACN,KAAK;qBACL,KAAK;6BACL,aAAa;QAGhC,IAAI,CAAC,kB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,YAAY,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAAC,IAAI,EAAE;gBAClD,QAAQ;gBACR,cAAc;gBACd,OAAO;aACR,CAAC,CAAA;YAEF,MAAM,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CACjE,CAAC,GAAG,EAAE,EAAE;gBACN,MAAM,mBAAmB,CAAC,IAAI,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAA;YAChE,CAAC,CACF,CAAA;YAED,MAAM,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,IAAI,CAAC,IAAI,EAAE;gBACpD,QAAQ;gBACR,cAAc;gBACd,OAAO;gBACP,KAAK;aACN,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import type { Did } from '@atproto/did'\nimport type { OAuthResolver } from '@atproto/oauth-resolver'\nimport {\n type OAuthIssuerIdentifier,\n isOAuthClientIdLoopback,\n} from '@atproto/oauth-types'\nimport { isAtIdentifierString } from '@atproto/syntax'\nimport type { ClientId } from '../client/client-id.js'\nimport type { Client } from '../client/client.js'\nimport type { DeviceId } from '../device/device-id.js'\nimport { InvalidCredentialsError } from '../errors/invalid-credentials-error.js'\nimport { InvalidRequestError } from '../errors/invalid-request-error.js'\nimport { UnknownAtprotoAccountError } from '../errors/unknown-atproto-account-error.js'\nimport { HCaptchaClient, type HcaptchaVerifyResult } from '../lib/hcaptcha.js'\nimport { callAsync } from '../lib/util/function.js'\nimport { constantTime } from '../lib/util/time.js'\nimport type { OAuthHooks, RequestMetadata } from '../oauth-hooks.js'\nimport type { Customization } from '../oauth-provider.js'\nimport type {\n Account,\n AccountStore,\n AtIdentifierString,\n AuthorizedClientData,\n AuthorizedClients,\n DeleteAccountConfirmInput,\n DeleteAccountRequestInput,\n DeviceAccount,\n DisableEmailAuthFactorInput,\n EnableEmailAuthFactorInput,\n HandleString,\n ResetPasswordConfirmInput,\n ResetPasswordRequestInput,\n SignUpData,\n UpdateEmailConfirmInput,\n UpdateEmailRequestInput,\n UpdateHandleData,\n VerifyEmailConfirmInput,\n VerifyEmailRequestInput,\n} from './account-store.js'\nimport type { SignInData } from './sign-in-data.js'\nimport type { SignUpInput } from './sign-up-input.js'\n\nconst TIMING_ATTACK_MITIGATION_DELAY = 400\nconst BRUTE_FORCE_MITIGATION_DELAY = 300\n\n// @TODO Add rate limit to all the OAuth routes.\n\nexport class AccountManager {\n protected readonly inviteCodeRequired: boolean\n protected readonly hcaptchaClient?: HCaptchaClient\n\n constructor(\n protected readonly issuer: OAuthIssuerIdentifier,\n protected readonly store: AccountStore,\n protected readonly hooks: OAuthHooks,\n protected readonly oauthResolver: OAuthResolver,\n customization: Customization,\n ) {\n this.inviteCodeRequired = customization.inviteCodeRequired !== false\n this.hcaptchaClient = customization.hcaptcha\n ? new HCaptchaClient(new URL(issuer).hostname, customization.hcaptcha)\n : undefined\n }\n\n protected async processHcaptchaToken(\n input: SignUpInput,\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n ): Promise<HcaptchaVerifyResult | undefined> {\n if (!this.hcaptchaClient) {\n return undefined\n }\n\n if (!input.hcaptchaToken) {\n throw new InvalidRequestError('hCaptcha token is required')\n }\n\n try {\n const tokens = await this.hcaptchaClient.buildClientTokens(\n deviceMetadata.ipAddress,\n input.handle,\n deviceMetadata.userAgent,\n )\n\n const result = await this.hcaptchaClient.verify(\n 'signup',\n input.hcaptchaToken,\n deviceMetadata.ipAddress,\n tokens,\n )\n\n await this.hooks.onHcaptchaResult?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n tokens,\n result,\n })\n\n this.hcaptchaClient.checkVerifyResult(result, tokens)\n\n return result\n } catch (err) {\n throw InvalidRequestError.from(err, 'hCaptcha verification failed')\n }\n }\n\n protected async enforceInviteCode(\n input: SignUpInput,\n _deviceId: DeviceId,\n _deviceMetadata: RequestMetadata,\n ): Promise<string | undefined> {\n if (!this.inviteCodeRequired) {\n return undefined\n }\n\n if (!input.inviteCode) {\n throw new InvalidRequestError('Invite code is required')\n }\n\n return input.inviteCode\n }\n\n protected async buildSignupData(\n input: SignUpInput,\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n ): Promise<SignUpData> {\n const [hcaptchaResult, inviteCode] = await Promise.all([\n this.processHcaptchaToken(input, deviceId, deviceMetadata),\n this.enforceInviteCode(input, deviceId, deviceMetadata),\n ])\n\n return { ...input, hcaptchaResult, inviteCode }\n }\n\n public async createAccount(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: SignUpInput,\n clientId?: ClientId,\n ): Promise<{ account: Account; remembered: boolean }> {\n return constantTime(BRUTE_FORCE_MITIGATION_DELAY, async () => {\n await callAsync(this.hooks.onSignUpAttempt, {\n input,\n deviceId,\n deviceMetadata,\n clientId,\n })\n\n const data = await this.buildSignupData(input, deviceId, deviceMetadata)\n\n const account = await callAsync(async () => {\n return this.store.createAccount(data)\n }).catch((err) => {\n throw InvalidRequestError.from(err, 'Account creation failed')\n })\n\n // @TODO Any error occurring below this point (server error most likely)\n // will not prevent the account from being created, but it will be\n // reported to the caller. We may want to wrap these errors in a way that\n // allows the UI to detect that a sign-up attempt will fail (\"account\n // already exists\"), and should provide appropriate feedback to the user\n // (eg. show sign-in form?).\n\n const isOAuthFlow = clientId != null\n const remembered = input.remember ?? !isOAuthFlow\n\n if (remembered) {\n await this.upsertDeviceAccount(deviceId, account.did)\n } else {\n // no need to remove the device account since it was never added (the\n // account was just created).\n }\n\n try {\n await callAsync(this.hooks.onSignedUp, {\n data,\n account,\n deviceId,\n deviceMetadata,\n clientId,\n })\n\n return { account, remembered }\n } catch (err) {\n // Delete the device account if an error occurred during the hook\n if (remembered) {\n await this.removeDeviceAccount(deviceId, account.did)\n }\n\n throw InvalidRequestError.from(\n err,\n 'The account was successfully created but something went wrong, try signing-in.',\n )\n }\n })\n }\n\n public async authenticateAccount(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n data: SignInData,\n clientId?: ClientId,\n ): Promise<{ account: Account; remembered: boolean }> {\n return constantTime(TIMING_ATTACK_MITIGATION_DELAY, async () => {\n // @NOTE If the user did not explicitly specify a \"remember\" preference,\n // we will use the existence of previously remembered device accounts to\n // determine the default \"remember\" behavior.\n const deviceAccounts = await this.listDeviceAccounts(deviceId)\n\n await this.hooks.onSignInAttempt?.call(null, {\n data,\n deviceId,\n deviceMetadata,\n deviceAccounts,\n clientId,\n })\n\n const account = await callAsync(async () => {\n return this.store.authenticateAccount({\n identifier: data.identifier,\n password: data.password,\n locale: data.locale,\n emailOtp: data.emailOtp,\n deviceAccounts,\n })\n }).catch(async (error) => {\n // Only notify for credential failures (e.g. unknown identifier, wrong\n // password). Server errors and flows that require an additional factor\n // (SecondAuthenticationFactorRequiredError) are not \"failed sign-ins\"\n // and do not trigger the hook.\n\n // Stores that throw the more specific `InvalidCredentialsError`\n // can attach the matched subject identifier to distinguish\n // \"identifier known, password wrong\" from \"identifier unknown\".\n if (error instanceof InvalidRequestError) {\n await this.hooks.onSignInFailed?.call(null, {\n data,\n error,\n did: error instanceof InvalidCredentialsError ? error.did : null,\n deviceId,\n deviceMetadata,\n clientId,\n })\n }\n\n throw error\n })\n\n const remembered =\n // If the user has explicitly specified a \"remember\" preference, use it.\n data.remember ??\n // Fall back to checking if the account was previously remembered.\n deviceAccounts.some((da) => da.account.did === account.did)\n\n if (remembered) {\n await this.upsertDeviceAccount(deviceId, account.did)\n } else {\n // In case the user was already signed in, and signed in again, this\n // time without \"remember me\", let's sign them off of the device.\n await this.removeDeviceAccount(deviceId, account.did)\n }\n\n try {\n await callAsync(this.hooks.onSignedIn, {\n data,\n account,\n remembered,\n deviceId,\n deviceMetadata,\n clientId,\n })\n\n return { account, remembered }\n } catch (err) {\n if (remembered) {\n await this.removeDeviceAccount(deviceId, account.did)\n }\n\n throw err\n }\n }).catch((err) => {\n throw InvalidRequestError.from(\n err,\n 'Unable to sign-in due to an unexpected server error',\n )\n })\n }\n\n public async signOut(deviceId: DeviceId, did: Did) {\n await this.removeDeviceAccount(deviceId, did)\n }\n\n protected async upsertDeviceAccount(\n deviceId: DeviceId,\n did: Did,\n ): Promise<void> {\n await this.store.upsertDeviceAccount(deviceId, did)\n }\n\n protected async removeDeviceAccount(deviceId: DeviceId, did: Did) {\n return this.store.removeDeviceAccount(deviceId, did)\n }\n\n public async getDeviceAccount(\n deviceId: DeviceId,\n did: Did,\n ): Promise<DeviceAccount> {\n const deviceAccount = await this.store.getDeviceAccount(deviceId, did)\n if (!deviceAccount) throw new InvalidRequestError(`Account not found`)\n\n return deviceAccount\n }\n\n public async setAuthorizedClient(\n account: Account,\n client: Client,\n data: AuthorizedClientData,\n ): Promise<void> {\n // \"Loopback\" clients are not distinguishable from one another.\n if (isOAuthClientIdLoopback(client.id)) return\n\n await this.store.setAuthorizedClient(account.did, client.id, data)\n }\n\n public async getAccount(did: Did): Promise<{\n account: Account\n authorizedClients: AuthorizedClients\n } | null> {\n return this.store.getAccount(did)\n }\n\n public async listDeviceAccounts(\n deviceId: DeviceId,\n ): Promise<DeviceAccount[]> {\n const deviceAccounts = await this.store.listDeviceAccounts({\n deviceId,\n })\n\n return deviceAccounts // Fool proof\n .filter((deviceAccount) => deviceAccount.deviceId === deviceId)\n }\n\n public async listAccountDevices(did: Did): Promise<DeviceAccount[]> {\n const deviceAccounts = await this.store.listDeviceAccounts({\n did,\n })\n\n return deviceAccounts // Fool proof\n .filter((deviceAccount) => deviceAccount.account.did === did)\n }\n\n public async resetPasswordRequest(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: ResetPasswordRequestInput,\n ): Promise<void> {\n // @NOTE We won't be sending reset password emails for non-email identifiers\n // (note that we might want to do that at some point, as other services,\n // e.g. Instagram, allow password reset via username). Supporting this would\n // require adding rate limiting + hCaptcha verification to prevent abuse.\n // Once those defense mechanisms are implemented, the whole \"if\" here after\n // can be removed as the \"if\" at the end of this function will handle\n // unknown accounts.\n if (isAtIdentifierString(input.identifier)) {\n // We *DO* however return a specific error message for users identified by\n // an at-identifier that are not hosted on this service.\n const result = await this.store.getAccount(input.identifier)\n if (!result) return this.throwUnknownAtmosphereAccount(input.identifier)\n\n throw new UnknownAtprotoAccountError(\n input.identifier,\n undefined,\n 'An email address is required for password reset',\n )\n }\n\n const account = await constantTime(\n TIMING_ATTACK_MITIGATION_DELAY,\n async () => {\n await this.hooks.onResetPasswordRequest?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n })\n\n const account = await this.store.resetPasswordRequest(input)\n\n // @NOTE Do not throw here, to prevent user enumeration\n\n await this.hooks.onResetPasswordRequested?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n account,\n })\n\n return account\n },\n )\n\n // @NOTE This is currently a dead branch (because of the \"if\" above) but\n // will become live once we support password reset via at-identifiers (by\n // removing the \"if\" at the beginning of this function.\n if (!account && isAtIdentifierString(input.identifier)) {\n return this.throwUnknownAtmosphereAccount(input.identifier)\n }\n }\n\n private async throwUnknownAtmosphereAccount(\n identifier: AtIdentifierString,\n ): Promise<never> {\n const { metadata, identityInfo } = await this.oauthResolver\n .resolve(identifier)\n .catch((cause: unknown) => {\n throw new UnknownAtprotoAccountError(\n identifier,\n undefined,\n undefined,\n cause,\n )\n })\n\n const handle =\n identityInfo?.handle === 'handle.invalid'\n ? undefined\n : identityInfo?.handle\n\n // The identity points back at this service (e.g. a taken-down account):\n // there is no other service to direct the user to.\n const issuer = metadata.issuer === this.issuer ? undefined : metadata.issuer\n\n throw new UnknownAtprotoAccountError(handle ?? identifier, issuer)\n }\n\n public async resetPasswordConfirm(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: ResetPasswordConfirmInput,\n ) {\n return constantTime(TIMING_ATTACK_MITIGATION_DELAY, async () => {\n await this.hooks.onResetPasswordConfirm?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n })\n\n const account = await this.store.resetPasswordConfirm(input)\n\n if (!account) {\n throw new InvalidRequestError('Invalid token')\n }\n\n await this.hooks.onResetPasswordConfirmed?.call(null, {\n input,\n deviceId,\n deviceMetadata,\n account,\n })\n\n return account\n })\n }\n\n public async verifyHandleAvailability(handle: HandleString): Promise<void> {\n return constantTime(TIMING_ATTACK_MITIGATION_DELAY, async () => {\n return this.store.verifyHandleAvailability(handle)\n })\n }\n\n public async updateEmailRequest(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: UpdateEmailRequestInput,\n account: Account,\n ): Promise<{ tokenRequired: boolean }> {\n await this.hooks.onChangeEmailRequest?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const { tokenRequired } = await this.store.updateEmailRequest(input)\n\n await this.hooks.onChangeEmailRequested?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n return { tokenRequired: tokenRequired === true }\n }\n\n public async updateEmailConfirm(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: UpdateEmailConfirmInput,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onUpdateEmailConfirm?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const updatedAccount = await this.store.updateEmailConfirm(input)\n\n if (!updatedAccount) {\n throw new InvalidRequestError('Invalid token')\n }\n\n await this.hooks.onUpdateEmailConfirmed?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account: updatedAccount,\n prevAccount: account,\n })\n\n return updatedAccount\n }\n\n public async verifyEmailRequest(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: VerifyEmailRequestInput,\n account: Account,\n ): Promise<void> {\n await this.hooks.onVerifyEmailRequest?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n input,\n })\n\n await this.store.verifyEmailRequest(input)\n\n await this.hooks.onVerifyEmailRequested?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n input,\n })\n }\n\n public async verifyEmailConfirm(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: VerifyEmailConfirmInput,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onVerifyEmailConfirm?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n input,\n })\n\n const updatedAccount = await this.store.verifyEmailConfirm(input)\n\n if (!updatedAccount) {\n throw new InvalidRequestError('Invalid token')\n }\n\n await this.hooks.onVerifyEmailConfirmed?.call(null, {\n deviceId,\n deviceMetadata,\n account: updatedAccount,\n input,\n })\n\n return updatedAccount\n }\n\n public async enableEmailAuthFactor(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: EnableEmailAuthFactorInput,\n account: Account,\n ): Promise<Account> {\n // Already enabled\n if (account.emailAuthFactor) return account\n\n await this.hooks.onEnableEmailAuthFactor?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const updatedAccount = await this.store.enableEmailAuthFactor(input)\n\n if (updatedAccount.emailAuthFactor !== account.emailAuthFactor) {\n await this.hooks.onEnabledEmailAuthFactor?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account: updatedAccount,\n })\n }\n\n return updatedAccount\n }\n\n public async disableEmailAuthFactor(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: DisableEmailAuthFactorInput,\n account: Account,\n ): Promise<Account> {\n // Already disabled\n if (!account.emailAuthFactor) return account\n\n await this.hooks.onDisableEmailAuthFactor?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const updatedAccount = await this.store.disableEmailAuthFactor(input)\n\n if (updatedAccount.emailAuthFactor !== account.emailAuthFactor) {\n await this.hooks.onDisabledEmailAuthFactor?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account: updatedAccount,\n })\n }\n\n return updatedAccount\n }\n\n public async updateHandle(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: UpdateHandleData,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onUpdateHandle?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account,\n })\n\n const updatedAccount = await this.store.updateHandle(input)\n\n await this.hooks.onUpdatedHandle?.call(null, {\n deviceId,\n deviceMetadata,\n input,\n account: updatedAccount,\n })\n\n return updatedAccount\n }\n\n public async deactivateAccount(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onDeactivateAccount?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n\n const updatedAccount = await callAsync(() =>\n this.store.deactivateAccount({\n did: account.did,\n // @TODO support setting this from the UI/API\n deleteAfter: undefined,\n }),\n ).catch((err) => {\n throw InvalidRequestError.from(err, 'Account deactivation failed')\n })\n\n await this.hooks.onDeactivatedAccount?.call(null, {\n deviceId,\n deviceMetadata,\n account: updatedAccount,\n })\n\n return updatedAccount\n }\n\n public async reactivateAccount(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n account: Account,\n ): Promise<Account> {\n await this.hooks.onReactivateAccount?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n\n const updatedAccount = await callAsync(() =>\n this.store.reactivateAccount({ did: account.did }),\n ).catch((err) => {\n throw InvalidRequestError.from(err, 'Account reactivation failed')\n })\n\n await this.hooks.onReactivatedAccount?.call(null, {\n deviceId,\n deviceMetadata,\n account: updatedAccount,\n })\n\n return updatedAccount\n }\n\n public async deleteAccountRequest(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: DeleteAccountRequestInput,\n account: Account,\n ): Promise<void> {\n await this.hooks.onDeleteAccountRequest?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n\n await this.store.deleteAccountRequest(input)\n\n await this.hooks.onDeleteAccountRequested?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n }\n\n public async deleteAccountConfirm(\n deviceId: DeviceId,\n deviceMetadata: RequestMetadata,\n input: DeleteAccountConfirmInput,\n account: Account,\n ): Promise<void> {\n return constantTime(BRUTE_FORCE_MITIGATION_DELAY, async () => {\n await this.hooks.onDeleteAccountConfirm?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n })\n\n await callAsync(() => this.store.deleteAccountConfirm(input)).catch(\n (err) => {\n throw InvalidRequestError.from(err, 'Account deletion failed')\n },\n )\n\n await this.hooks.onDeleteAccountConfirmed?.call(null, {\n deviceId,\n deviceMetadata,\n account,\n input,\n })\n })\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Did } from '@atproto/did';
|
|
2
2
|
import type { Account, ConfirmAccountDeletionInput, ConfirmEmailUpdateInput, ConfirmEmailVerificationInput, ConfirmResetPasswordInput, DeactivateAccountInput, DisableEmailAuthFactorInput, EnableEmailAuthFactorInput, InitiateAccountDeletionInput, InitiateEmailUpdateInput, InitiateEmailUpdateOutput, InitiateEmailVerificationInput, InitiatePasswordResetInput, ReactivateAccountInput, UpdateHandleInput } from '@atproto/oauth-provider-api';
|
|
3
3
|
import type { OAuthScope } from '@atproto/oauth-types';
|
|
4
|
-
import type
|
|
4
|
+
import { type AtIdentifierString, type DatetimeString, type HandleString, isAtIdentifierString, isDidIdentifier } from '@atproto/syntax';
|
|
5
5
|
import type { ClientId } from '../client/client-id.js';
|
|
6
6
|
import type { DeviceData } from '../device/device-data.js';
|
|
7
7
|
import type { DeviceId } from '../device/device-id.js';
|
|
@@ -9,9 +9,11 @@ import type { SessionId } from '../device/session-id.js';
|
|
|
9
9
|
import type { HandleUnavailableReason } from '../errors/handle-unavailable-error.js';
|
|
10
10
|
import type { HcaptchaVerifyResult } from '../lib/hcaptcha.js';
|
|
11
11
|
import type { Awaitable } from '../lib/util/type.js';
|
|
12
|
+
import type { IdentifierString } from '../types/indentifier.js';
|
|
12
13
|
import type { InviteCode } from '../types/invite-code.js';
|
|
13
14
|
import type { SignUpInput } from './sign-up-input.js';
|
|
14
|
-
export type { Account, ClientId, DeviceData, DeviceId, Did, DisableEmailAuthFactorInput, EnableEmailAuthFactorInput, HandleString, HandleUnavailableReason, HcaptchaVerifyResult, InviteCode, OAuthScope, SessionId, SignUpInput, };
|
|
15
|
+
export type { Account, AtIdentifierString, ClientId, DeviceData, DeviceId, Did, DisableEmailAuthFactorInput, EnableEmailAuthFactorInput, HandleString, HandleUnavailableReason, HcaptchaVerifyResult, IdentifierString, InviteCode, OAuthScope, SessionId, SignUpInput, };
|
|
16
|
+
export { isAtIdentifierString, isDidIdentifier };
|
|
15
17
|
export type ResetPasswordRequestInput = InitiatePasswordResetInput;
|
|
16
18
|
export type ResetPasswordConfirmInput = ConfirmResetPasswordInput;
|
|
17
19
|
export type UpdateEmailRequestInput = InitiateEmailUpdateInput;
|
|
@@ -38,9 +40,9 @@ export type CreateAccountData = {
|
|
|
38
40
|
inviteCode?: string | undefined;
|
|
39
41
|
};
|
|
40
42
|
export type AuthenticateAccountData = {
|
|
41
|
-
|
|
43
|
+
identifier: IdentifierString;
|
|
42
44
|
password: string;
|
|
43
|
-
|
|
45
|
+
locale: string;
|
|
44
46
|
emailOtp: string | undefined;
|
|
45
47
|
/**
|
|
46
48
|
* Lists the accounts that were previously remembered on the device, allowing
|
|
@@ -103,9 +105,10 @@ export interface AccountStore {
|
|
|
103
105
|
*/
|
|
104
106
|
setAuthorizedClient(did: Did, clientId: ClientId, data: AuthorizedClientData): Awaitable<void>;
|
|
105
107
|
/**
|
|
106
|
-
*
|
|
108
|
+
* Retrieves the account and its authorized clients for the given handle or
|
|
109
|
+
* DID. Return `null` if the account is not found.
|
|
107
110
|
*/
|
|
108
|
-
getAccount(
|
|
111
|
+
getAccount(handleOrDid: AtIdentifierString): Awaitable<null | {
|
|
109
112
|
account: Account;
|
|
110
113
|
authorizedClients: AuthorizedClients;
|
|
111
114
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-store.d.ts","sourceRoot":"","sources":["../../src/account/account-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,EACV,OAAO,EACP,2BAA2B,EAC3B,uBAAuB,E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AAE,uBAAuB,GAAG,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAE5E;;;;;;;;;;;OAWG;IACH,qBAAqB,CAAC,IAAI,EAAE,0BAA0B,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IAE3E;;;;;;;;;;;;;;;;;;OAkBG;IACH,sBAAsB,CAAC,IAAI,EAAE,2BAA2B,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IAE7E;;OAEG;IACH,wBAAwB,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;IAE/D;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IAExD;;;;;;OAMG;IACH,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IAElE;;;;;;OAMG;IACH,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IAElE;;;;;OAKG;IACH,oBAAoB,CAAC,IAAI,EAAE,yBAAyB,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;IAEtE;;;;;;OAMG;IACH,oBAAoB,CAAC,IAAI,EAAE,yBAAyB,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;CACvE;AAED,eAAO,MAAM,cAAc,yHAuBzB,CAAA;AAEF,wBAAgB,cAAc,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,GAAG,CAAC,GAAG,YAAY,CAKrE"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { isAtIdentifierString, isDidIdentifier, } from '@atproto/syntax';
|
|
1
2
|
import { buildInterfaceChecker } from '../lib/util/type.js';
|
|
3
|
+
export { isAtIdentifierString, isDidIdentifier };
|
|
2
4
|
export const isAccountStore = buildInterfaceChecker([
|
|
3
5
|
'authenticateAccount',
|
|
4
6
|
'createAccount',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-store.js","sourceRoot":"","sources":["../../src/account/account-store.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AA2R3D,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAe;IAChE,qBAAqB;IACrB,eAAe;IACf,mBAAmB;IACnB,sBAAsB;IACtB,sBAAsB;IACtB,wBAAwB;IACxB,uBAAuB;IACvB,YAAY;IACZ,kBAAkB;IAClB,oBAAoB;IACpB,mBAAmB;IACnB,qBAAqB;IACrB,sBAAsB;IACtB,sBAAsB;IACtB,qBAAqB;IACrB,oBAAoB;IACpB,oBAAoB;IACpB,cAAc;IACd,qBAAqB;IACrB,oBAAoB;IACpB,oBAAoB;IACpB,0BAA0B;CAC3B,CAAC,CAAA;AAEF,MAAM,UAAU,cAAc,CAAI,cAAiB;IACjD,IAAI,CAAC,cAAc,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,cAAc,CAAA;AACvB,CAAC","sourcesContent":["import type { Did } from '@atproto/did'\nimport type {\n Account,\n ConfirmAccountDeletionInput,\n ConfirmEmailUpdateInput,\n ConfirmEmailVerificationInput,\n ConfirmResetPasswordInput,\n DeactivateAccountInput,\n DisableEmailAuthFactorInput,\n EnableEmailAuthFactorInput,\n InitiateAccountDeletionInput,\n InitiateEmailUpdateInput,\n InitiateEmailUpdateOutput,\n InitiateEmailVerificationInput,\n InitiatePasswordResetInput,\n ReactivateAccountInput,\n UpdateHandleInput,\n} from '@atproto/oauth-provider-api'\nimport type { OAuthScope } from '@atproto/oauth-types'\nimport type { DatetimeString, HandleString } from '@atproto/syntax'\nimport type { ClientId } from '../client/client-id.js'\nimport type { DeviceData } from '../device/device-data.js'\nimport type { DeviceId } from '../device/device-id.js'\nimport type { SessionId } from '../device/session-id.js'\nimport type { HandleUnavailableReason } from '../errors/handle-unavailable-error.js'\nimport type { HcaptchaVerifyResult } from '../lib/hcaptcha.js'\nimport type { Awaitable } from '../lib/util/type.js'\nimport { buildInterfaceChecker } from '../lib/util/type.js'\nimport type { InviteCode } from '../types/invite-code.js'\nimport type { SignUpInput } from './sign-up-input.js'\n\n// Export all types needed to implement the AccountStore interface\nexport type {\n Account,\n ClientId,\n DeviceData,\n DeviceId,\n Did,\n DisableEmailAuthFactorInput,\n EnableEmailAuthFactorInput,\n HandleString,\n HandleUnavailableReason,\n HcaptchaVerifyResult,\n InviteCode,\n OAuthScope,\n SessionId,\n SignUpInput,\n}\n\nexport type ResetPasswordRequestInput = InitiatePasswordResetInput\nexport type ResetPasswordConfirmInput = ConfirmResetPasswordInput\n\nexport type UpdateEmailRequestInput = InitiateEmailUpdateInput\nexport type UpdateEmailRequestOutput = InitiateEmailUpdateOutput\nexport type UpdateEmailConfirmInput = ConfirmEmailUpdateInput\nexport type VerifyEmailRequestInput = InitiateEmailVerificationInput\nexport type VerifyEmailConfirmInput = ConfirmEmailVerificationInput\nexport type UpdateHandleData = UpdateHandleInput\n\n/**\n * @NOTE `deleteAfter` is part of the store contract but is not (yet) exposed\n * over the API, hence the extension of {@link DeactivateAccountInput}.\n */\nexport type DeactivateAccountData = DeactivateAccountInput & {\n deleteAfter?: DatetimeString | undefined\n}\nexport type ReactivateAccountData = ReactivateAccountInput\nexport type DeleteAccountRequestInput = InitiateAccountDeletionInput\nexport type DeleteAccountConfirmInput = ConfirmAccountDeletionInput\n\nexport type CreateAccountData = {\n locale: string\n email: string\n password: string\n handle: HandleString\n inviteCode?: string | undefined\n}\n\nexport type AuthenticateAccountData = {\n locale: string\n password: string\n username: string\n emailOtp: string | undefined\n /**\n * Lists the accounts that were previously remembered on the device, allowing\n * OTP bypass for these accounts (based on the store's own logic)\n */\n deviceAccounts: readonly DeviceAccount[]\n}\n\nexport type AuthorizedClientData = { authorizedScopes: readonly string[] }\nexport type AuthorizedClients = Map<ClientId, AuthorizedClientData>\n\nexport type DeviceAccount = {\n deviceId: DeviceId\n\n /**\n * The data associated with the device, created through the\n * {@link DeviceStore}. This data is used to identify devices on which a user\n * has logged in.\n */\n deviceData: DeviceData\n\n /**\n * The account associated with the device account.\n */\n account: Account\n\n /**\n * The list of clients that are authorized by the account, as created through\n * the {@link AccountStore.setAuthorizedClient} method.\n */\n authorizedClients: AuthorizedClients\n\n /**\n * The date at which the device account was created. This value is currently\n * not used.\n */\n createdAt: Date\n\n /**\n * The date at which the device account was last updated. This value is used\n * to determine the date at which the user last authenticated on a device\n */\n updatedAt: Date\n}\n\nexport type SignUpData = SignUpInput & {\n hcaptchaResult?: HcaptchaVerifyResult\n inviteCode?: InviteCode\n}\n\nexport interface AccountStore {\n /**\n * @throws {HandleUnavailableError} - To indicate that the handle is already taken\n * @throws {InvalidRequestError} - To indicate that some data is invalid\n */\n createAccount(data: CreateAccountData): Awaitable<Account>\n\n /**\n * @throws {InvalidCredentialsError} - When the credentials are not valid.\n * Populate {@link InvalidCredentialsError.did} with the subject identifier\n * when the identifier matched an existing account (e.g. wrong password for a\n * known user); omit it when the identifier was not found.\n * @throws {SecondAuthenticationFactorRequiredError} - To indicate that an {@link SecondAuthenticationFactorRequiredError.type} is required in the credentials\n */\n authenticateAccount(data: AuthenticateAccountData): Awaitable<Account>\n\n /**\n * Add a client & scopes to the list of authorized clients for the given account.\n */\n setAuthorizedClient(\n did: Did,\n clientId: ClientId,\n data: AuthorizedClientData,\n ): Awaitable<void>\n\n /**\n * @throws {InvalidRequestError} - When the credentials are not valid\n */\n getAccount(did: Did): Awaitable<{\n account: Account\n authorizedClients: AuthorizedClients\n }>\n\n /**\n * @param data.requestId - If provided, the inserted account must be bound to\n * that particular requestId.\n *\n * @note Whenever a particular device account is created, all **unbound**\n * device accounts for the same `deviceId` & `sub` should be deleted.\n *\n * @note When a particular request is deleted (through\n * {@link RequestStore.deleteRequest}), all accounts bound to that request\n * should be deleted as well.\n */\n upsertDeviceAccount(deviceId: DeviceId, did: Did): Awaitable<void>\n\n /**\n * @param requestId - If provided, the result must either have the same\n * requestId, or not be bound to a particular requestId. If `null`, the\n * result must not be bound to a particular requestId.\n * @throws {InvalidRequestError} - Instead of returning `null` in order to\n * provide a custom error message\n */\n getDeviceAccount(\n deviceId: DeviceId,\n did: Did,\n ): Awaitable<DeviceAccount | null>\n\n /**\n * Removes *all* the unbound device-accounts associated with the given device\n * & account.\n *\n * @note Noop if the device-account is not found.\n */\n removeDeviceAccount(deviceId: DeviceId, did: Did): Awaitable<void>\n\n /**\n * @returns **all** the device accounts matching the given `filter`.\n */\n listDeviceAccounts(\n filter: { did: Did } | { deviceId: DeviceId },\n ): Awaitable<DeviceAccount[]>\n\n resetPasswordRequest(\n data: ResetPasswordRequestInput,\n ): Awaitable<null | Account>\n\n resetPasswordConfirm(\n data: ResetPasswordConfirmInput,\n ): Awaitable<null | Account>\n\n updateEmailRequest(\n data: UpdateEmailRequestInput,\n ): Awaitable<UpdateEmailRequestOutput>\n /**\n * Must trigger a verification email to be sent to the new email address, that\n * will then be confirmed through {@link updateEmailConfirm}. The account's\n * {@link Account['emailVerified'] emailVerified} field is expected to become\n * `false` until the new email is confirmed.\n */\n updateEmailConfirm(data: UpdateEmailConfirmInput): Awaitable<Account | null>\n\n verifyEmailRequest(data: VerifyEmailRequestInput): Awaitable<void>\n verifyEmailConfirm(data: VerifyEmailConfirmInput): Awaitable<Account | null>\n\n /**\n * Enables the email auth factor on the account.\n *\n * @returns the updated account, or `null` when the factor was already enabled\n * (no-op).\n *\n * @note when `null` is returned (no-op), the \"confirmed\" hook is skipped, so\n * a repeat request is not counted as a fresh opt-in.\n *\n * @throws {InvalidRequestError} - To indicate enabling cannot take place due\n * to mismatch of email or email not being verified.\n */\n enableEmailAuthFactor(data: EnableEmailAuthFactorInput): Awaitable<Account>\n\n /**\n * Two-phase disable flow. When `token` is undefined and the factor is still\n * enabled, an email-based OTP isÒ dispatched and `{ tokenRequired: true }` is\n * returned (the account is unchanged, nothing has been disabled yet). Calling\n * again with a valid `token` disables the factor and returns\n * `{ tokenRequired: false }`. Disabling an already-disabled factor is an\n * idempotent no-op that returns `{ tokenRequired: false }` without\n * dispatching an email.\n *\n * `updatedAccount` is `null` in both cases where nothing changed — the\n * OTP-dispatch phase and the already-disabled no-op — and an `Account` only\n * once the factor has actually been turned off. Callers pair it with\n * `tokenRequired` to decide whether to fire the \"confirmed\" hook.\n *\n * @throws {InvalidRequestError} - To indicate disabling cannot take place due\n * to mismatch of email or email not being verified.\n * @throws {SecondAuthenticationFactorRequiredError} - To indicate that a\n * second authentication factor is required to complete the action.\n */\n disableEmailAuthFactor(data: DisableEmailAuthFactorInput): Awaitable<Account>\n\n /**\n * @throws {HandleUnavailableError} - To indicate that the handle is already taken\n */\n verifyHandleAvailability(handle: HandleString): Awaitable<void>\n\n /**\n * @throws {HandleUnavailableError} - To indicate that the handle is already taken\n * @throws {InvalidRequestError} - To indicate that the handle is invalid or\n * cannot be used\n */\n updateHandle(data: UpdateHandleData): Awaitable<Account>\n\n /**\n * Mark the account as deactivated. The account remains recoverable. Should\n * be a no-op when the account is already deactivated.\n *\n * @throws {InvalidRequestError} - When the account cannot be deactivated\n * (e.g. unknown account)\n */\n deactivateAccount(data: DeactivateAccountData): Awaitable<Account>\n\n /**\n * Reactivate a previously-deactivated account. Should be a no-op when the\n * account is already active.\n *\n * @throws {InvalidRequestError} - When the account cannot be reactivated\n * (e.g. unknown account)\n */\n reactivateAccount(data: ReactivateAccountData): Awaitable<Account>\n\n /**\n * Initiate account deletion: typically sends a confirmation token to the\n * account's email address. The account is NOT deleted until\n * {@link deleteAccountConfirm} is called with the matching token and the\n * user's current password.\n */\n deleteAccountRequest(data: DeleteAccountRequestInput): Awaitable<void>\n\n /**\n * Finalize account deletion. Implementations MUST verify both the email\n * confirmation `token` issued by {@link deleteAccountRequest} and the user's\n * current `password` before deleting any data. Deletion is irreversible.\n *\n * @throws {InvalidRequestError} - When the token or password is invalid.\n */\n deleteAccountConfirm(data: DeleteAccountConfirmInput): Awaitable<void>\n}\n\nexport const isAccountStore = buildInterfaceChecker<AccountStore>([\n 'authenticateAccount',\n 'createAccount',\n 'deactivateAccount',\n 'deleteAccountConfirm',\n 'deleteAccountRequest',\n 'disableEmailAuthFactor',\n 'enableEmailAuthFactor',\n 'getAccount',\n 'getDeviceAccount',\n 'listDeviceAccounts',\n 'reactivateAccount',\n 'removeDeviceAccount',\n 'resetPasswordConfirm',\n 'resetPasswordRequest',\n 'setAuthorizedClient',\n 'updateEmailConfirm',\n 'updateEmailRequest',\n 'updateHandle',\n 'upsertDeviceAccount',\n 'verifyEmailConfirm',\n 'verifyEmailRequest',\n 'verifyHandleAvailability',\n])\n\nexport function asAccountStore<V>(implementation: V): V & AccountStore {\n if (!implementation || !isAccountStore(implementation)) {\n throw new Error('Invalid AccountStore implementation')\n }\n return implementation\n}\n"]}
|
|
1
|
+
{"version":3,"file":"account-store.js","sourceRoot":"","sources":["../../src/account/account-store.ts"],"names":[],"mappings":"AAmBA,OAAO,EAIL,oBAAoB,EACpB,eAAe,GAChB,MAAM,iBAAiB,CAAA;AAQxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAyB3D,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,CAAA;AAwQhD,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAe;IAChE,qBAAqB;IACrB,eAAe;IACf,mBAAmB;IACnB,sBAAsB;IACtB,sBAAsB;IACtB,wBAAwB;IACxB,uBAAuB;IACvB,YAAY;IACZ,kBAAkB;IAClB,oBAAoB;IACpB,mBAAmB;IACnB,qBAAqB;IACrB,sBAAsB;IACtB,sBAAsB;IACtB,qBAAqB;IACrB,oBAAoB;IACpB,oBAAoB;IACpB,cAAc;IACd,qBAAqB;IACrB,oBAAoB;IACpB,oBAAoB;IACpB,0BAA0B;CAC3B,CAAC,CAAA;AAEF,MAAM,UAAU,cAAc,CAAI,cAAiB;IACjD,IAAI,CAAC,cAAc,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,cAAc,CAAA;AACvB,CAAC","sourcesContent":["import type { Did } from '@atproto/did'\nimport type {\n Account,\n ConfirmAccountDeletionInput,\n ConfirmEmailUpdateInput,\n ConfirmEmailVerificationInput,\n ConfirmResetPasswordInput,\n DeactivateAccountInput,\n DisableEmailAuthFactorInput,\n EnableEmailAuthFactorInput,\n InitiateAccountDeletionInput,\n InitiateEmailUpdateInput,\n InitiateEmailUpdateOutput,\n InitiateEmailVerificationInput,\n InitiatePasswordResetInput,\n ReactivateAccountInput,\n UpdateHandleInput,\n} from '@atproto/oauth-provider-api'\nimport type { OAuthScope } from '@atproto/oauth-types'\nimport {\n type AtIdentifierString,\n type DatetimeString,\n type HandleString,\n isAtIdentifierString,\n isDidIdentifier,\n} from '@atproto/syntax'\nimport type { ClientId } from '../client/client-id.js'\nimport type { DeviceData } from '../device/device-data.js'\nimport type { DeviceId } from '../device/device-id.js'\nimport type { SessionId } from '../device/session-id.js'\nimport type { HandleUnavailableReason } from '../errors/handle-unavailable-error.js'\nimport type { HcaptchaVerifyResult } from '../lib/hcaptcha.js'\nimport type { Awaitable } from '../lib/util/type.js'\nimport { buildInterfaceChecker } from '../lib/util/type.js'\nimport type { IdentifierString } from '../types/indentifier.js'\nimport type { InviteCode } from '../types/invite-code.js'\nimport type { SignUpInput } from './sign-up-input.js'\n\n// Export all types needed to implement the AccountStore interface\nexport type {\n Account,\n AtIdentifierString,\n ClientId,\n DeviceData,\n DeviceId,\n Did,\n DisableEmailAuthFactorInput,\n EnableEmailAuthFactorInput,\n HandleString,\n HandleUnavailableReason,\n HcaptchaVerifyResult,\n IdentifierString,\n InviteCode,\n OAuthScope,\n SessionId,\n SignUpInput,\n}\n\nexport { isAtIdentifierString, isDidIdentifier }\n\nexport type ResetPasswordRequestInput = InitiatePasswordResetInput\nexport type ResetPasswordConfirmInput = ConfirmResetPasswordInput\n\nexport type UpdateEmailRequestInput = InitiateEmailUpdateInput\nexport type UpdateEmailRequestOutput = InitiateEmailUpdateOutput\nexport type UpdateEmailConfirmInput = ConfirmEmailUpdateInput\nexport type VerifyEmailRequestInput = InitiateEmailVerificationInput\nexport type VerifyEmailConfirmInput = ConfirmEmailVerificationInput\nexport type UpdateHandleData = UpdateHandleInput\n\n/**\n * @NOTE `deleteAfter` is part of the store contract but is not (yet) exposed\n * over the API, hence the extension of {@link DeactivateAccountInput}.\n */\nexport type DeactivateAccountData = DeactivateAccountInput & {\n deleteAfter?: DatetimeString | undefined\n}\nexport type ReactivateAccountData = ReactivateAccountInput\nexport type DeleteAccountRequestInput = InitiateAccountDeletionInput\nexport type DeleteAccountConfirmInput = ConfirmAccountDeletionInput\n\nexport type CreateAccountData = {\n locale: string\n email: string\n password: string\n handle: HandleString\n inviteCode?: string | undefined\n}\n\nexport type AuthenticateAccountData = {\n identifier: IdentifierString\n password: string\n locale: string\n emailOtp: string | undefined\n /**\n * Lists the accounts that were previously remembered on the device, allowing\n * OTP bypass for these accounts (based on the store's own logic)\n */\n deviceAccounts: readonly DeviceAccount[]\n}\n\nexport type AuthorizedClientData = { authorizedScopes: readonly string[] }\nexport type AuthorizedClients = Map<ClientId, AuthorizedClientData>\n\nexport type DeviceAccount = {\n deviceId: DeviceId\n\n /**\n * The data associated with the device, created through the\n * {@link DeviceStore}. This data is used to identify devices on which a user\n * has logged in.\n */\n deviceData: DeviceData\n\n /**\n * The account associated with the device account.\n */\n account: Account\n\n /**\n * The list of clients that are authorized by the account, as created through\n * the {@link AccountStore.setAuthorizedClient} method.\n */\n authorizedClients: AuthorizedClients\n\n /**\n * The date at which the device account was created. This value is currently\n * not used.\n */\n createdAt: Date\n\n /**\n * The date at which the device account was last updated. This value is used\n * to determine the date at which the user last authenticated on a device\n */\n updatedAt: Date\n}\n\nexport type SignUpData = SignUpInput & {\n hcaptchaResult?: HcaptchaVerifyResult\n inviteCode?: InviteCode\n}\n\nexport interface AccountStore {\n /**\n * @throws {HandleUnavailableError} - To indicate that the handle is already taken\n * @throws {InvalidRequestError} - To indicate that some data is invalid\n */\n createAccount(data: CreateAccountData): Awaitable<Account>\n\n /**\n * @throws {InvalidCredentialsError} - When the credentials are not valid.\n * Populate {@link InvalidCredentialsError.did} with the subject identifier\n * when the identifier matched an existing account (e.g. wrong password for a\n * known user); omit it when the identifier was not found.\n * @throws {SecondAuthenticationFactorRequiredError} - To indicate that an {@link SecondAuthenticationFactorRequiredError.type} is required in the credentials\n */\n authenticateAccount(data: AuthenticateAccountData): Awaitable<Account>\n\n /**\n * Add a client & scopes to the list of authorized clients for the given account.\n */\n setAuthorizedClient(\n did: Did,\n clientId: ClientId,\n data: AuthorizedClientData,\n ): Awaitable<void>\n\n /**\n * Retrieves the account and its authorized clients for the given handle or\n * DID. Return `null` if the account is not found.\n */\n getAccount(handleOrDid: AtIdentifierString): Awaitable<null | {\n account: Account\n authorizedClients: AuthorizedClients\n }>\n\n /**\n * @param data.requestId - If provided, the inserted account must be bound to\n * that particular requestId.\n *\n * @note Whenever a particular device account is created, all **unbound**\n * device accounts for the same `deviceId` & `sub` should be deleted.\n *\n * @note When a particular request is deleted (through\n * {@link RequestStore.deleteRequest}), all accounts bound to that request\n * should be deleted as well.\n */\n upsertDeviceAccount(deviceId: DeviceId, did: Did): Awaitable<void>\n\n /**\n * @param requestId - If provided, the result must either have the same\n * requestId, or not be bound to a particular requestId. If `null`, the\n * result must not be bound to a particular requestId.\n * @throws {InvalidRequestError} - Instead of returning `null` in order to\n * provide a custom error message\n */\n getDeviceAccount(\n deviceId: DeviceId,\n did: Did,\n ): Awaitable<DeviceAccount | null>\n\n /**\n * Removes *all* the unbound device-accounts associated with the given device\n * & account.\n *\n * @note Noop if the device-account is not found.\n */\n removeDeviceAccount(deviceId: DeviceId, did: Did): Awaitable<void>\n\n /**\n * @returns **all** the device accounts matching the given `filter`.\n */\n listDeviceAccounts(\n filter: { did: Did } | { deviceId: DeviceId },\n ): Awaitable<DeviceAccount[]>\n\n resetPasswordRequest(\n data: ResetPasswordRequestInput,\n ): Awaitable<null | Account>\n\n resetPasswordConfirm(\n data: ResetPasswordConfirmInput,\n ): Awaitable<null | Account>\n\n updateEmailRequest(\n data: UpdateEmailRequestInput,\n ): Awaitable<UpdateEmailRequestOutput>\n /**\n * Must trigger a verification email to be sent to the new email address, that\n * will then be confirmed through {@link updateEmailConfirm}. The account's\n * {@link Account['emailVerified'] emailVerified} field is expected to become\n * `false` until the new email is confirmed.\n */\n updateEmailConfirm(data: UpdateEmailConfirmInput): Awaitable<Account | null>\n\n verifyEmailRequest(data: VerifyEmailRequestInput): Awaitable<void>\n verifyEmailConfirm(data: VerifyEmailConfirmInput): Awaitable<Account | null>\n\n /**\n * Enables the email auth factor on the account.\n *\n * @returns the updated account, or `null` when the factor was already enabled\n * (no-op).\n *\n * @note when `null` is returned (no-op), the \"confirmed\" hook is skipped, so\n * a repeat request is not counted as a fresh opt-in.\n *\n * @throws {InvalidRequestError} - To indicate enabling cannot take place due\n * to mismatch of email or email not being verified.\n */\n enableEmailAuthFactor(data: EnableEmailAuthFactorInput): Awaitable<Account>\n\n /**\n * Two-phase disable flow. When `token` is undefined and the factor is still\n * enabled, an email-based OTP isÒ dispatched and `{ tokenRequired: true }` is\n * returned (the account is unchanged, nothing has been disabled yet). Calling\n * again with a valid `token` disables the factor and returns\n * `{ tokenRequired: false }`. Disabling an already-disabled factor is an\n * idempotent no-op that returns `{ tokenRequired: false }` without\n * dispatching an email.\n *\n * `updatedAccount` is `null` in both cases where nothing changed — the\n * OTP-dispatch phase and the already-disabled no-op — and an `Account` only\n * once the factor has actually been turned off. Callers pair it with\n * `tokenRequired` to decide whether to fire the \"confirmed\" hook.\n *\n * @throws {InvalidRequestError} - To indicate disabling cannot take place due\n * to mismatch of email or email not being verified.\n * @throws {SecondAuthenticationFactorRequiredError} - To indicate that a\n * second authentication factor is required to complete the action.\n */\n disableEmailAuthFactor(data: DisableEmailAuthFactorInput): Awaitable<Account>\n\n /**\n * @throws {HandleUnavailableError} - To indicate that the handle is already taken\n */\n verifyHandleAvailability(handle: HandleString): Awaitable<void>\n\n /**\n * @throws {HandleUnavailableError} - To indicate that the handle is already taken\n * @throws {InvalidRequestError} - To indicate that the handle is invalid or\n * cannot be used\n */\n updateHandle(data: UpdateHandleData): Awaitable<Account>\n\n /**\n * Mark the account as deactivated. The account remains recoverable. Should\n * be a no-op when the account is already deactivated.\n *\n * @throws {InvalidRequestError} - When the account cannot be deactivated\n * (e.g. unknown account)\n */\n deactivateAccount(data: DeactivateAccountData): Awaitable<Account>\n\n /**\n * Reactivate a previously-deactivated account. Should be a no-op when the\n * account is already active.\n *\n * @throws {InvalidRequestError} - When the account cannot be reactivated\n * (e.g. unknown account)\n */\n reactivateAccount(data: ReactivateAccountData): Awaitable<Account>\n\n /**\n * Initiate account deletion: typically sends a confirmation token to the\n * account's email address. The account is NOT deleted until\n * {@link deleteAccountConfirm} is called with the matching token and the\n * user's current password.\n */\n deleteAccountRequest(data: DeleteAccountRequestInput): Awaitable<void>\n\n /**\n * Finalize account deletion. Implementations MUST verify both the email\n * confirmation `token` issued by {@link deleteAccountRequest} and the user's\n * current `password` before deleting any data. Deletion is irreversible.\n *\n * @throws {InvalidRequestError} - When the token or password is invalid.\n */\n deleteAccountConfirm(data: DeleteAccountConfirmInput): Awaitable<void>\n}\n\nexport const isAccountStore = buildInterfaceChecker<AccountStore>([\n 'authenticateAccount',\n 'createAccount',\n 'deactivateAccount',\n 'deleteAccountConfirm',\n 'deleteAccountRequest',\n 'disableEmailAuthFactor',\n 'enableEmailAuthFactor',\n 'getAccount',\n 'getDeviceAccount',\n 'listDeviceAccounts',\n 'reactivateAccount',\n 'removeDeviceAccount',\n 'resetPasswordConfirm',\n 'resetPasswordRequest',\n 'setAuthorizedClient',\n 'updateEmailConfirm',\n 'updateEmailRequest',\n 'updateHandle',\n 'upsertDeviceAccount',\n 'verifyEmailConfirm',\n 'verifyEmailRequest',\n 'verifyHandleAvailability',\n])\n\nexport function asAccountStore<V>(implementation: V): V & AccountStore {\n if (!implementation || !isAccountStore(implementation)) {\n throw new Error('Invalid AccountStore implementation')\n }\n return implementation\n}\n"]}
|
|
@@ -8,7 +8,7 @@ import { isAtprotoDid } from '@atproto/did';
|
|
|
8
8
|
*/
|
|
9
9
|
export async function resolveLoginHint(hint, accountManager) {
|
|
10
10
|
if (hint && isAtprotoDid(hint)) {
|
|
11
|
-
const account = await accountManager.getAccount(hint).then((result) => result.account,
|
|
11
|
+
const account = await accountManager.getAccount(hint).then((result) => (result ? result.account : null),
|
|
12
12
|
// Unknown account: fall back to displaying the hint as-is
|
|
13
13
|
() => null);
|
|
14
14
|
if (account?.handle)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-hint.js","sourceRoot":"","sources":["../../src/account/login-hint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAG3C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAwB,EACxB,cAAkD;IAElD,IAAI,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CACxD,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"login-hint.js","sourceRoot":"","sources":["../../src/account/login-hint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAG3C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAwB,EACxB,cAAkD;IAElD,IAAI,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CACxD,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5C,0DAA0D;QAC1D,GAAG,EAAE,CAAC,IAAI,CACX,CAAA;QACD,IAAI,OAAO,EAAE,MAAM;YAAE,OAAO,OAAO,CAAC,MAAM,CAAA;IAC5C,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { isAtprotoDid } from '@atproto/did'\nimport type { AccountManager } from './account-manager.js'\n\n/**\n * Computes the user-facing value for a `login_hint` request parameter. Clients\n * may provide a DID (typically when re-authenticating an account they already\n * know), which users are unlikely to recognize as their own. When the DID\n * belongs to an account on this server, return that account's current handle\n * for display instead.\n */\nexport async function resolveLoginHint(\n hint: string | undefined,\n accountManager: Pick<AccountManager, 'getAccount'>,\n): Promise<string | undefined> {\n if (hint && isAtprotoDid(hint)) {\n const account = await accountManager.getAccount(hint).then(\n (result) => (result ? result.account : null),\n // Unknown account: fall back to displaying the hint as-is\n () => null,\n )\n if (account?.handle) return account.handle\n }\n\n return hint\n}\n"]}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const signInDataSchema: z.ZodObject<{
|
|
3
3
|
locale: z.ZodString;
|
|
4
|
-
|
|
4
|
+
identifier: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, `${string}@${string}`, string>, `${string}@${string}`, string>, z.ZodEffects<z.ZodString, `did:${string}:${string}`, string>, z.ZodEffects<z.ZodString, `${string}.${string}`, string>]>;
|
|
5
5
|
password: z.ZodUnion<[z.ZodString, z.ZodString]>;
|
|
6
6
|
emailOtp: z.ZodOptional<z.ZodString>;
|
|
7
7
|
remember: z.ZodOptional<z.ZodBoolean>;
|
|
8
8
|
}, "strict", z.ZodTypeAny, {
|
|
9
9
|
locale: string;
|
|
10
|
-
|
|
10
|
+
identifier: `${string}.${string}` | `${string}@${string}` | `did:${string}:${string}`;
|
|
11
11
|
password: string;
|
|
12
12
|
emailOtp?: string | undefined;
|
|
13
13
|
remember?: boolean | undefined;
|
|
14
14
|
}, {
|
|
15
15
|
locale: string;
|
|
16
|
-
|
|
16
|
+
identifier: string;
|
|
17
17
|
password: string;
|
|
18
18
|
emailOtp?: string | undefined;
|
|
19
19
|
remember?: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign-in-data.d.ts","sourceRoot":"","sources":["../../src/account/sign-in-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"sign-in-data.d.ts","sourceRoot":"","sources":["../../src/account/sign-in-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;EAQlB,CAAA;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAA"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { localeSchema } from '../lib/util/locale.js';
|
|
3
3
|
import { emailOtpSchema } from '../types/email-otp.js';
|
|
4
|
+
import { identifierSchema } from '../types/indentifier.js';
|
|
4
5
|
import { newPasswordSchema, oldPasswordSchema } from '../types/password.js';
|
|
5
6
|
export const signInDataSchema = z
|
|
6
7
|
.object({
|
|
7
8
|
locale: localeSchema,
|
|
8
|
-
|
|
9
|
+
identifier: identifierSchema,
|
|
9
10
|
password: z.union([oldPasswordSchema, newPasswordSchema]),
|
|
10
11
|
emailOtp: emailOtpSchema.optional(),
|
|
11
12
|
remember: z.boolean().optional(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign-in-data.js","sourceRoot":"","sources":["../../src/account/sign-in-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACN,MAAM,EAAE,YAAY;IACpB,
|
|
1
|
+
{"version":3,"file":"sign-in-data.js","sourceRoot":"","sources":["../../src/account/sign-in-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACN,MAAM,EAAE,YAAY;IACpB,UAAU,EAAE,gBAAgB;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IACzD,QAAQ,EAAE,cAAc,CAAC,QAAQ,EAAE;IACnC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC;KACD,MAAM,EAAE,CAAA","sourcesContent":["import { z } from 'zod'\nimport { localeSchema } from '../lib/util/locale.js'\nimport { emailOtpSchema } from '../types/email-otp.js'\nimport { identifierSchema } from '../types/indentifier.js'\nimport { newPasswordSchema, oldPasswordSchema } from '../types/password.js'\n\nexport const signInDataSchema = z\n .object({\n locale: localeSchema,\n identifier: identifierSchema,\n password: z.union([oldPasswordSchema, newPasswordSchema]),\n emailOtp: emailOtpSchema.optional(),\n remember: z.boolean().optional(),\n })\n .strict()\n\nexport type SignInData = z.output<typeof signInDataSchema>\n"]}
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
export declare const signUpInputSchema: z.ZodObject<{
|
|
3
3
|
locale: z.ZodString;
|
|
4
4
|
handle: z.ZodEffects<z.ZodString, `${string}.${string}`, string>;
|
|
5
|
-
email: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, string
|
|
5
|
+
email: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, `${string}@${string}`, string>, `${string}@${string}`, string>, `${string}@${string}`, string>;
|
|
6
6
|
password: z.ZodString;
|
|
7
7
|
remember: z.ZodOptional<z.ZodBoolean>;
|
|
8
8
|
inviteCode: z.ZodOptional<z.ZodString>;
|
|
@@ -10,7 +10,7 @@ export declare const signUpInputSchema: z.ZodObject<{
|
|
|
10
10
|
}, "strict", z.ZodTypeAny, {
|
|
11
11
|
locale: string;
|
|
12
12
|
handle: `${string}.${string}`;
|
|
13
|
-
email: string
|
|
13
|
+
email: `${string}@${string}`;
|
|
14
14
|
password: string;
|
|
15
15
|
remember?: boolean | undefined;
|
|
16
16
|
inviteCode?: string | undefined;
|