@atproto/oauth-provider 0.2.16 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +34 -0
- package/dist/account/account-store.d.ts +1 -1
- package/dist/account/account-store.d.ts.map +1 -1
- package/dist/account/account-store.js +6 -9
- package/dist/account/account-store.js.map +1 -1
- package/dist/account/account.d.ts +1 -1
- package/dist/account/account.d.ts.map +1 -1
- package/dist/assets/app/bundle-manifest.json +2 -2
- package/dist/assets/app/main.js +1 -1
- package/dist/assets/app/main.js.map +1 -1
- package/dist/assets/assets-middleware.d.ts.map +1 -1
- package/dist/assets/assets-middleware.js.map +1 -1
- package/dist/assets/index.d.ts.map +1 -1
- package/dist/assets/index.js +7 -6
- package/dist/assets/index.js.map +1 -1
- package/dist/client/client-auth.d.ts +1 -1
- package/dist/client/client-auth.d.ts.map +1 -1
- package/dist/client/client-auth.js +1 -1
- package/dist/client/client-auth.js.map +1 -1
- package/dist/client/client-manager.d.ts +2 -2
- package/dist/client/client-manager.d.ts.map +1 -1
- package/dist/client/client-manager.js +8 -10
- package/dist/client/client-manager.js.map +1 -1
- package/dist/client/client-store.d.ts.map +1 -1
- package/dist/client/client-store.js.map +1 -1
- package/dist/client/client-utils.d.ts.map +1 -1
- package/dist/client/client-utils.js.map +1 -1
- package/dist/client/client.d.ts +1 -1
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +1 -1
- package/dist/client/client.js.map +1 -1
- package/dist/device/device-data.d.ts +7 -8
- package/dist/device/device-data.d.ts.map +1 -1
- package/dist/device/device-data.js +3 -2
- package/dist/device/device-data.js.map +1 -1
- package/dist/device/device-id.d.ts.map +1 -1
- package/dist/device/device-id.js.map +1 -1
- package/dist/device/device-manager.d.ts +104 -19
- package/dist/device/device-manager.d.ts.map +1 -1
- package/dist/device/device-manager.js +44 -31
- package/dist/device/device-manager.js.map +1 -1
- package/dist/device/session-id.d.ts.map +1 -1
- package/dist/device/session-id.js.map +1 -1
- package/dist/dpop/dpop-manager.d.ts.map +1 -1
- package/dist/dpop/dpop-manager.js.map +1 -1
- package/dist/dpop/dpop-nonce.d.ts.map +1 -1
- package/dist/dpop/dpop-nonce.js.map +1 -1
- package/dist/errors/invalid-client-metadata-error.js +1 -1
- package/dist/errors/invalid-client-metadata-error.js.map +1 -1
- package/dist/errors/invalid-token-error.d.ts.map +1 -1
- package/dist/errors/invalid-token-error.js +1 -1
- package/dist/errors/invalid-token-error.js.map +1 -1
- package/dist/errors/www-authenticate-error.d.ts.map +1 -1
- package/dist/errors/www-authenticate-error.js.map +1 -1
- package/dist/lib/http/accept.d.ts +2 -1
- package/dist/lib/http/accept.d.ts.map +1 -1
- package/dist/lib/http/accept.js.map +1 -1
- package/dist/lib/http/method.d.ts +1 -1
- package/dist/lib/http/method.d.ts.map +1 -1
- package/dist/lib/http/middleware.d.ts +1 -1
- package/dist/lib/http/middleware.d.ts.map +1 -1
- package/dist/lib/http/request.d.ts +10 -1
- package/dist/lib/http/request.d.ts.map +1 -1
- package/dist/lib/http/request.js +40 -2
- package/dist/lib/http/request.js.map +1 -1
- package/dist/lib/http/response.d.ts +3 -2
- package/dist/lib/http/response.d.ts.map +1 -1
- package/dist/lib/http/response.js.map +1 -1
- package/dist/lib/http/route.d.ts +2 -1
- package/dist/lib/http/route.d.ts.map +1 -1
- package/dist/lib/http/route.js.map +1 -1
- package/dist/lib/http/router.d.ts +2 -1
- package/dist/lib/http/router.d.ts.map +1 -1
- package/dist/lib/http/router.js.map +1 -1
- package/dist/lib/http/stream.d.ts +1 -1
- package/dist/lib/http/stream.d.ts.map +1 -1
- package/dist/lib/http/stream.js +1 -1
- package/dist/lib/http/stream.js.map +1 -1
- package/dist/lib/http/types.d.ts +0 -1
- package/dist/lib/http/types.d.ts.map +1 -1
- package/dist/lib/util/authorization-header.d.ts.map +1 -1
- package/dist/lib/util/authorization-header.js +1 -1
- package/dist/lib/util/authorization-header.js.map +1 -1
- package/dist/lib/util/function.d.ts +8 -0
- package/dist/lib/util/function.d.ts.map +1 -1
- package/dist/lib/util/function.js +1 -1
- package/dist/lib/util/function.js.map +1 -1
- package/dist/lib/util/hostname.d.ts.map +1 -1
- package/dist/lib/util/time.d.ts +7 -1
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +23 -12
- package/dist/lib/util/time.js.map +1 -1
- package/dist/metadata/build-metadata.d.ts.map +1 -1
- package/dist/metadata/build-metadata.js.map +1 -1
- package/dist/oauth-hooks.d.ts +56 -4
- package/dist/oauth-hooks.d.ts.map +1 -1
- package/dist/oauth-hooks.js +8 -0
- package/dist/oauth-hooks.js.map +1 -1
- package/dist/oauth-provider.d.ts +13 -10
- package/dist/oauth-provider.d.ts.map +1 -1
- package/dist/oauth-provider.js +36 -58
- package/dist/oauth-provider.js.map +1 -1
- package/dist/oauth-verifier.d.ts +1 -1
- package/dist/oauth-verifier.d.ts.map +1 -1
- package/dist/oauth-verifier.js.map +1 -1
- package/dist/output/build-authorize-data.d.ts.map +1 -1
- package/dist/output/build-authorize-data.js.map +1 -1
- package/dist/output/build-error-payload.d.ts.map +1 -1
- package/dist/output/build-error-payload.js +1 -1
- package/dist/output/build-error-payload.js.map +1 -1
- package/dist/output/output-manager.d.ts +1 -1
- package/dist/output/output-manager.d.ts.map +1 -1
- package/dist/output/output-manager.js.map +1 -1
- package/dist/output/send-authorize-redirect.d.ts +1 -1
- package/dist/output/send-authorize-redirect.d.ts.map +1 -1
- package/dist/output/send-authorize-redirect.js.map +1 -1
- package/dist/output/send-web-page.d.ts +1 -1
- package/dist/output/send-web-page.d.ts.map +1 -1
- package/dist/output/send-web-page.js.map +1 -1
- package/dist/replay/replay-store-redis.d.ts.map +1 -1
- package/dist/replay/replay-store-redis.js.map +1 -1
- package/dist/request/code.d.ts.map +1 -1
- package/dist/request/code.js.map +1 -1
- package/dist/request/request-data.d.ts.map +1 -1
- package/dist/request/request-data.js.map +1 -1
- package/dist/request/request-id.d.ts.map +1 -1
- package/dist/request/request-id.js.map +1 -1
- package/dist/request/request-info.d.ts +1 -1
- package/dist/request/request-info.d.ts.map +1 -1
- package/dist/request/request-manager.d.ts +2 -1
- package/dist/request/request-manager.d.ts.map +1 -1
- package/dist/request/request-manager.js +10 -2
- package/dist/request/request-manager.js.map +1 -1
- package/dist/request/request-store-memory.d.ts +1 -1
- package/dist/request/request-store-memory.d.ts.map +1 -1
- package/dist/request/request-store-redis.d.ts +1 -1
- package/dist/request/request-store-redis.d.ts.map +1 -1
- package/dist/request/request-store-redis.js.map +1 -1
- package/dist/request/request-uri.d.ts.map +1 -1
- package/dist/request/request-uri.js.map +1 -1
- package/dist/signer/signed-token-payload.d.ts +1 -1
- package/dist/signer/signed-token-payload.d.ts.map +1 -1
- package/dist/signer/signed-token-payload.js +2 -5
- package/dist/signer/signed-token-payload.js.map +1 -1
- package/dist/signer/signer.d.ts +1 -1
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js.map +1 -1
- package/dist/token/refresh-token.d.ts.map +1 -1
- package/dist/token/refresh-token.js.map +1 -1
- package/dist/token/token-claims.d.ts +1 -1
- package/dist/token/token-claims.d.ts.map +1 -1
- package/dist/token/token-claims.js +2 -5
- package/dist/token/token-claims.js.map +1 -1
- package/dist/token/token-data.d.ts.map +1 -1
- package/dist/token/token-id.d.ts.map +1 -1
- package/dist/token/token-id.js.map +1 -1
- package/dist/token/token-manager.d.ts +3 -2
- package/dist/token/token-manager.d.ts.map +1 -1
- package/dist/token/token-manager.js +40 -25
- package/dist/token/token-manager.js.map +1 -1
- package/dist/token/verify-token-claims.d.ts.map +1 -1
- package/dist/token/verify-token-claims.js.map +1 -1
- package/package.json +13 -12
- package/rollup.config.js +4 -5
- package/src/account/account-store.ts +1 -2
- package/src/account/account.ts +1 -1
- package/src/assets/app/hooks/use-api.ts +1 -2
- package/src/assets/app/lib/api.ts +0 -1
- package/src/assets/assets-middleware.ts +0 -1
- package/src/assets/index.ts +2 -3
- package/src/client/client-auth.ts +1 -2
- package/src/client/client-manager.ts +22 -25
- package/src/client/client-store.ts +0 -1
- package/src/client/client-utils.ts +0 -1
- package/src/client/client.ts +13 -14
- package/src/device/device-data.ts +3 -3
- package/src/device/device-id.ts +0 -1
- package/src/device/device-manager.ts +94 -79
- package/src/device/session-id.ts +0 -1
- package/src/dpop/dpop-manager.ts +0 -2
- package/src/dpop/dpop-nonce.ts +0 -1
- package/src/errors/invalid-client-metadata-error.ts +1 -1
- package/src/errors/invalid-token-error.ts +1 -2
- package/src/errors/www-authenticate-error.ts +0 -1
- package/src/lib/http/accept.ts +2 -7
- package/src/lib/http/method.ts +1 -1
- package/src/lib/http/middleware.ts +1 -1
- package/src/lib/http/request.ts +66 -4
- package/src/lib/http/response.ts +3 -3
- package/src/lib/http/route.ts +2 -1
- package/src/lib/http/router.ts +2 -1
- package/src/lib/http/stream.ts +4 -5
- package/src/lib/http/types.ts +0 -1
- package/src/lib/util/authorization-header.ts +1 -2
- package/src/lib/util/function.ts +19 -2
- package/src/lib/util/hostname.ts +1 -1
- package/src/lib/util/time.ts +35 -18
- package/src/metadata/build-metadata.ts +0 -1
- package/src/oauth-hooks.ts +73 -14
- package/src/oauth-provider.ts +77 -37
- package/src/oauth-verifier.ts +1 -2
- package/src/output/build-authorize-data.ts +0 -1
- package/src/output/build-error-payload.ts +1 -2
- package/src/output/output-manager.ts +3 -4
- package/src/output/send-authorize-redirect.ts +1 -2
- package/src/output/send-web-page.ts +3 -4
- package/src/replay/replay-manager.ts +1 -1
- package/src/replay/replay-store-redis.ts +0 -1
- package/src/request/code.ts +0 -1
- package/src/request/request-data.ts +0 -1
- package/src/request/request-id.ts +0 -1
- package/src/request/request-info.ts +1 -1
- package/src/request/request-manager.ts +16 -6
- package/src/request/request-store-memory.ts +1 -1
- package/src/request/request-store-redis.ts +1 -2
- package/src/request/request-uri.ts +0 -1
- package/src/signer/signed-token-payload.ts +1 -2
- package/src/signer/signer.ts +1 -2
- package/src/token/refresh-token.ts +0 -1
- package/src/token/token-claims.ts +1 -2
- package/src/token/token-data.ts +0 -1
- package/src/token/token-id.ts +0 -1
- package/src/token/token-manager.ts +53 -25
- package/src/token/verify-token-claims.ts +0 -1
- package/tsconfig.backend.tsbuildinfo +1 -1
- package/dist/device/device-details.d.ts +0 -16
- package/dist/device/device-details.d.ts.map +0 -1
- package/dist/device/device-details.js +0 -34
- package/dist/device/device-details.js.map +0 -1
- package/src/device/device-details.ts +0 -43
@@ -3,7 +3,6 @@ import {
|
|
3
3
|
OAuthAuthorizationRequestParameters,
|
4
4
|
OAuthAuthorizationServerMetadata,
|
5
5
|
} from '@atproto/oauth-types'
|
6
|
-
|
7
6
|
import { Account } from '../account/account.js'
|
8
7
|
import { ClientAuth } from '../client/client-auth.js'
|
9
8
|
import { ClientId } from '../client/client-id.js'
|
@@ -20,22 +19,24 @@ import { InvalidAuthorizationDetailsError } from '../errors/invalid-authorizatio
|
|
20
19
|
import { InvalidGrantError } from '../errors/invalid-grant-error.js'
|
21
20
|
import { InvalidParametersError } from '../errors/invalid-parameters-error.js'
|
22
21
|
import { InvalidRequestError } from '../errors/invalid-request-error.js'
|
22
|
+
import { InvalidScopeError } from '../errors/invalid-scope-error.js'
|
23
|
+
import { RequestMetadata } from '../lib/http/request.js'
|
24
|
+
import { callAsync } from '../lib/util/function.js'
|
23
25
|
import { OAuthHooks } from '../oauth-hooks.js'
|
24
26
|
import { Signer } from '../signer/signer.js'
|
25
27
|
import { Code, generateCode } from './code.js'
|
26
28
|
import {
|
27
|
-
isRequestDataAuthorized,
|
28
29
|
RequestDataAuthorized,
|
30
|
+
isRequestDataAuthorized,
|
29
31
|
} from './request-data.js'
|
30
32
|
import { generateRequestId } from './request-id.js'
|
31
33
|
import { RequestInfo } from './request-info.js'
|
32
34
|
import { RequestStore, UpdateRequestData } from './request-store.js'
|
33
35
|
import {
|
36
|
+
RequestUri,
|
34
37
|
decodeRequestUri,
|
35
38
|
encodeRequestUri,
|
36
|
-
RequestUri,
|
37
39
|
} from './request-uri.js'
|
38
|
-
import { InvalidScopeError } from '../errors/invalid-scope-error.js'
|
39
40
|
|
40
41
|
export class RequestManager {
|
41
42
|
constructor(
|
@@ -370,10 +371,11 @@ export class RequestManager {
|
|
370
371
|
}
|
371
372
|
|
372
373
|
async setAuthorized(
|
373
|
-
client: Client,
|
374
374
|
uri: RequestUri,
|
375
|
-
|
375
|
+
client: Client,
|
376
376
|
account: Account,
|
377
|
+
deviceId: DeviceId,
|
378
|
+
deviceMetadata: RequestMetadata,
|
377
379
|
): Promise<Code> {
|
378
380
|
const id = decodeRequestUri(uri)
|
379
381
|
|
@@ -414,6 +416,14 @@ export class RequestManager {
|
|
414
416
|
expiresAt: new Date(Date.now() + AUTHORIZATION_INACTIVITY_TIMEOUT),
|
415
417
|
})
|
416
418
|
|
419
|
+
await callAsync(this.hooks.onAuthorized, {
|
420
|
+
client,
|
421
|
+
account,
|
422
|
+
parameters: data.parameters,
|
423
|
+
deviceId,
|
424
|
+
deviceMetadata,
|
425
|
+
})
|
426
|
+
|
417
427
|
return code
|
418
428
|
} catch (err) {
|
419
429
|
await this.store.deleteRequest(id)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Code } from './code.js'
|
2
|
-
import { RequestId } from './request-id.js'
|
3
2
|
import { RequestData } from './request-data.js'
|
3
|
+
import { RequestId } from './request-id.js'
|
4
4
|
import { RequestStore } from './request-store.js'
|
5
5
|
|
6
6
|
export class RequestStoreMemory implements RequestStore {
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import type { Redis } from 'ioredis'
|
2
|
-
|
3
2
|
import { CreateRedisOptions, createRedis } from '../lib/redis.js'
|
4
3
|
import { Code } from './code.js'
|
5
4
|
import { RequestData } from './request-data.js'
|
6
5
|
import { RequestId, requestIdSchema } from './request-id.js'
|
7
6
|
import { RequestStore } from './request-store.js'
|
8
7
|
|
9
|
-
export type {
|
8
|
+
export type { CreateRedisOptions, Redis }
|
10
9
|
|
11
10
|
export type ReplayStoreRedisOptions = {
|
12
11
|
redis: CreateRedisOptions
|
package/src/signer/signer.ts
CHANGED
@@ -7,10 +7,9 @@ import {
|
|
7
7
|
VerifyOptions,
|
8
8
|
} from '@atproto/jwk'
|
9
9
|
import {
|
10
|
-
OAuthAuthorizationRequestParameters,
|
11
10
|
OAuthAuthorizationDetails,
|
11
|
+
OAuthAuthorizationRequestParameters,
|
12
12
|
} from '@atproto/oauth-types'
|
13
|
-
|
14
13
|
import { Client } from '../client/client.js'
|
15
14
|
import { dateToEpoch } from '../lib/util/date.js'
|
16
15
|
import { TokenId } from '../token/token-id.js'
|
package/src/token/token-data.ts
CHANGED
@@ -2,7 +2,6 @@ import {
|
|
2
2
|
OAuthAuthorizationDetails,
|
3
3
|
OAuthAuthorizationRequestParameters,
|
4
4
|
} from '@atproto/oauth-types'
|
5
|
-
|
6
5
|
import { ClientAuth } from '../client/client-auth.js'
|
7
6
|
import { ClientId } from '../client/client-id.js'
|
8
7
|
import { DeviceId } from '../device/device-id.js'
|
package/src/token/token-id.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { createHash } from 'node:crypto'
|
1
2
|
import { isSignedJwt } from '@atproto/jwk'
|
2
3
|
import {
|
3
4
|
CLIENT_ASSERTION_TYPE_JWT_BEARER,
|
@@ -10,8 +11,6 @@ import {
|
|
10
11
|
OAuthTokenResponse,
|
11
12
|
OAuthTokenType,
|
12
13
|
} from '@atproto/oauth-types'
|
13
|
-
import { createHash } from 'node:crypto'
|
14
|
-
|
15
14
|
import { AccessTokenType } from '../access-token/access-token-type.js'
|
16
15
|
import { DeviceAccountInfo } from '../account/account-store.js'
|
17
16
|
import { Account } from '../account/account.js'
|
@@ -30,6 +29,7 @@ import { InvalidDpopProofError } from '../errors/invalid-dpop-proof-error.js'
|
|
30
29
|
import { InvalidGrantError } from '../errors/invalid-grant-error.js'
|
31
30
|
import { InvalidRequestError } from '../errors/invalid-request-error.js'
|
32
31
|
import { InvalidTokenError } from '../errors/invalid-token-error.js'
|
32
|
+
import { RequestMetadata } from '../lib/http/request.js'
|
33
33
|
import { dateToEpoch, dateToRelativeSeconds } from '../lib/util/date.js'
|
34
34
|
import { callAsync } from '../lib/util/function.js'
|
35
35
|
import { OAuthHooks } from '../oauth-hooks.js'
|
@@ -83,6 +83,7 @@ export class TokenManager {
|
|
83
83
|
async create(
|
84
84
|
client: Client,
|
85
85
|
clientAuth: ClientAuth,
|
86
|
+
clientMetadata: RequestMetadata,
|
86
87
|
account: Account,
|
87
88
|
device: null | { id: DeviceId; info: DeviceAccountInfo },
|
88
89
|
parameters: OAuthAuthorizationRequestParameters,
|
@@ -208,13 +209,16 @@ export class TokenManager {
|
|
208
209
|
const now = new Date()
|
209
210
|
const expiresAt = this.createTokenExpiry(now)
|
210
211
|
|
211
|
-
const authorizationDetails =
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
212
|
+
const authorizationDetails = await callAsync(
|
213
|
+
this.hooks.getAuthorizationDetails,
|
214
|
+
{
|
215
|
+
client,
|
216
|
+
clientAuth,
|
217
|
+
clientMetadata,
|
218
|
+
parameters,
|
219
|
+
account,
|
220
|
+
},
|
221
|
+
)
|
218
222
|
|
219
223
|
const tokenData: TokenData = {
|
220
224
|
createdAt: now,
|
@@ -247,7 +251,7 @@ export class TokenManager {
|
|
247
251
|
authorization_details: authorizationDetails,
|
248
252
|
})
|
249
253
|
|
250
|
-
|
254
|
+
const response = await this.buildTokenResponse(
|
251
255
|
client,
|
252
256
|
accessToken,
|
253
257
|
refreshToken,
|
@@ -256,6 +260,17 @@ export class TokenManager {
|
|
256
260
|
account,
|
257
261
|
authorizationDetails,
|
258
262
|
)
|
263
|
+
|
264
|
+
await callAsync(this.hooks.onTokenCreated, {
|
265
|
+
client,
|
266
|
+
clientAuth,
|
267
|
+
clientMetadata,
|
268
|
+
account,
|
269
|
+
parameters,
|
270
|
+
deviceId: device ? device.id : null,
|
271
|
+
})
|
272
|
+
|
273
|
+
return response
|
259
274
|
} catch (err) {
|
260
275
|
// Just in case the token could not be issued, we delete it from the store
|
261
276
|
await this.store.deleteToken(tokenId)
|
@@ -317,6 +332,7 @@ export class TokenManager {
|
|
317
332
|
async refresh(
|
318
333
|
client: Client,
|
319
334
|
clientAuth: ClientAuth,
|
335
|
+
clientMetadata: RequestMetadata,
|
320
336
|
input: OAuthRefreshTokenGrantTokenRequest,
|
321
337
|
dpopJkt: null | string,
|
322
338
|
): Promise<OAuthTokenResponse> {
|
@@ -378,13 +394,16 @@ export class TokenManager {
|
|
378
394
|
throw new InvalidGrantError(`Refresh token expired`)
|
379
395
|
}
|
380
396
|
|
381
|
-
const
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
397
|
+
const authorizationDetails = await callAsync(
|
398
|
+
this.hooks.getAuthorizationDetails,
|
399
|
+
{
|
400
|
+
client,
|
401
|
+
clientAuth,
|
402
|
+
clientMetadata,
|
403
|
+
parameters,
|
404
|
+
account,
|
405
|
+
},
|
406
|
+
)
|
388
407
|
|
389
408
|
const nextTokenId = await generateTokenId()
|
390
409
|
const nextRefreshToken = await generateRefreshToken()
|
@@ -427,24 +446,33 @@ export class TokenManager {
|
|
427
446
|
iat: now,
|
428
447
|
jti: nextTokenId,
|
429
448
|
cnf: parameters.dpop_jkt ? { jkt: parameters.dpop_jkt } : undefined,
|
430
|
-
authorization_details,
|
449
|
+
authorization_details: authorizationDetails,
|
431
450
|
})
|
432
451
|
|
433
|
-
|
452
|
+
const response = await this.buildTokenResponse(
|
434
453
|
client,
|
435
454
|
accessToken,
|
436
455
|
nextRefreshToken,
|
437
456
|
expiresAt,
|
438
457
|
parameters,
|
439
458
|
account,
|
440
|
-
|
459
|
+
authorizationDetails,
|
441
460
|
)
|
461
|
+
|
462
|
+
await callAsync(this.hooks.onTokenRefreshed, {
|
463
|
+
client,
|
464
|
+
clientAuth,
|
465
|
+
clientMetadata,
|
466
|
+
account,
|
467
|
+
parameters,
|
468
|
+
deviceId: tokenInfo.data.deviceId,
|
469
|
+
})
|
470
|
+
|
471
|
+
return response
|
442
472
|
} catch (err) {
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
await this.store.deleteToken(tokenInfo.id)
|
447
|
-
}
|
473
|
+
// Just in case the token could not be refreshed, we delete it from the store
|
474
|
+
await this.store.deleteToken(tokenInfo.id)
|
475
|
+
|
448
476
|
throw err
|
449
477
|
}
|
450
478
|
}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { OAuthAccessToken, OAuthTokenType } from '@atproto/oauth-types'
|
2
|
-
|
3
2
|
import { InvalidDpopKeyBindingError } from '../errors/invalid-dpop-key-binding-error.js'
|
4
3
|
import { InvalidDpopProofError } from '../errors/invalid-dpop-proof-error.js'
|
5
4
|
import { asArray } from '../lib/util/cast.js'
|
@@ -1 +1 @@
|
|
1
|
-
{"root":["./src/constants.ts","./src/index.ts","./src/oauth-client.ts","./src/oauth-dpop.ts","./src/oauth-errors.ts","./src/oauth-hooks.ts","./src/oauth-provider.ts","./src/oauth-store.ts","./src/oauth-verifier.ts","./src/access-token/access-token-type.ts","./src/account/account-manager.ts","./src/account/account-store.ts","./src/account/account.ts","./src/assets/asset.ts","./src/assets/assets-middleware.ts","./src/assets/index.ts","./src/client/client-auth.ts","./src/client/client-data.ts","./src/client/client-id.ts","./src/client/client-info.ts","./src/client/client-manager.ts","./src/client/client-store.ts","./src/client/client-utils.ts","./src/client/client.ts","./src/device/device-data.ts","./src/device/device-
|
1
|
+
{"root":["./src/constants.ts","./src/index.ts","./src/oauth-client.ts","./src/oauth-dpop.ts","./src/oauth-errors.ts","./src/oauth-hooks.ts","./src/oauth-provider.ts","./src/oauth-store.ts","./src/oauth-verifier.ts","./src/access-token/access-token-type.ts","./src/account/account-manager.ts","./src/account/account-store.ts","./src/account/account.ts","./src/assets/asset.ts","./src/assets/assets-middleware.ts","./src/assets/index.ts","./src/client/client-auth.ts","./src/client/client-data.ts","./src/client/client-id.ts","./src/client/client-info.ts","./src/client/client-manager.ts","./src/client/client-store.ts","./src/client/client-utils.ts","./src/client/client.ts","./src/device/device-data.ts","./src/device/device-id.ts","./src/device/device-manager.ts","./src/device/device-store.ts","./src/device/session-id.ts","./src/dpop/dpop-manager.ts","./src/dpop/dpop-nonce.ts","./src/errors/access-denied-error.ts","./src/errors/account-selection-required-error.ts","./src/errors/consent-required-error.ts","./src/errors/invalid-authorization-details-error.ts","./src/errors/invalid-client-error.ts","./src/errors/invalid-client-id-error.ts","./src/errors/invalid-client-metadata-error.ts","./src/errors/invalid-dpop-key-binding-error.ts","./src/errors/invalid-dpop-proof-error.ts","./src/errors/invalid-grant-error.ts","./src/errors/invalid-parameters-error.ts","./src/errors/invalid-redirect-uri-error.ts","./src/errors/invalid-request-error.ts","./src/errors/invalid-scope-error.ts","./src/errors/invalid-token-error.ts","./src/errors/login-required-error.ts","./src/errors/oauth-error.ts","./src/errors/second-authentication-factor-required-error.ts","./src/errors/unauthorized-client-error.ts","./src/errors/use-dpop-nonce-error.ts","./src/errors/www-authenticate-error.ts","./src/lib/redis.ts","./src/lib/html/build-document.ts","./src/lib/html/escapers.ts","./src/lib/html/html.ts","./src/lib/html/index.ts","./src/lib/html/tags.ts","./src/lib/html/util.ts","./src/lib/http/accept.ts","./src/lib/http/context.ts","./src/lib/http/index.ts","./src/lib/http/method.ts","./src/lib/http/middleware.ts","./src/lib/http/parser.ts","./src/lib/http/path.ts","./src/lib/http/request.ts","./src/lib/http/response.ts","./src/lib/http/route.ts","./src/lib/http/router.ts","./src/lib/http/stream.ts","./src/lib/http/types.ts","./src/lib/http/url.ts","./src/lib/util/authorization-header.ts","./src/lib/util/cast.ts","./src/lib/util/crypto.ts","./src/lib/util/date.ts","./src/lib/util/function.ts","./src/lib/util/hostname.ts","./src/lib/util/redirect-uri.ts","./src/lib/util/time.ts","./src/lib/util/type.ts","./src/lib/util/well-known.ts","./src/metadata/build-metadata.ts","./src/oidc/sub.ts","./src/output/build-authorize-data.ts","./src/output/build-error-payload.ts","./src/output/customization.ts","./src/output/output-manager.ts","./src/output/send-authorize-redirect.ts","./src/output/send-web-page.ts","./src/replay/replay-manager.ts","./src/replay/replay-store-memory.ts","./src/replay/replay-store-redis.ts","./src/replay/replay-store.ts","./src/request/code.ts","./src/request/request-data.ts","./src/request/request-id.ts","./src/request/request-info.ts","./src/request/request-manager.ts","./src/request/request-store-memory.ts","./src/request/request-store-redis.ts","./src/request/request-store.ts","./src/request/request-uri.ts","./src/signer/signed-token-payload.ts","./src/signer/signer.ts","./src/token/refresh-token.ts","./src/token/token-claims.ts","./src/token/token-data.ts","./src/token/token-id.ts","./src/token/token-manager.ts","./src/token/token-store.ts","./src/token/verify-token-claims.ts"],"version":"5.6.3"}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { IncomingMessage } from 'node:http';
|
2
|
-
import { z } from 'zod';
|
3
|
-
export declare const deviceDetailsSchema: z.ZodObject<{
|
4
|
-
userAgent: z.ZodNullable<z.ZodString>;
|
5
|
-
ipAddress: z.ZodString;
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
7
|
-
userAgent: string | null;
|
8
|
-
ipAddress: string;
|
9
|
-
}, {
|
10
|
-
userAgent: string | null;
|
11
|
-
ipAddress: string;
|
12
|
-
}>;
|
13
|
-
export type DeviceDetails = z.infer<typeof deviceDetailsSchema>;
|
14
|
-
export declare function extractDeviceDetails(req: IncomingMessage, trustProxy: boolean): DeviceDetails;
|
15
|
-
export declare function extractIpAddress(req: IncomingMessage, trustProxy: boolean): string | undefined;
|
16
|
-
//# sourceMappingURL=device-details.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"device-details.d.ts","sourceRoot":"","sources":["../../src/device/device-details.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,mBAAmB;;;;;;;;;EAG9B,CAAA;AACF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAE/D,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,eAAe,EACpB,UAAU,EAAE,OAAO,GAClB,aAAa,CASf;AAED,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,eAAe,EACpB,UAAU,EAAE,OAAO,GAClB,MAAM,GAAG,SAAS,CAepB"}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.deviceDetailsSchema = void 0;
|
4
|
-
exports.extractDeviceDetails = extractDeviceDetails;
|
5
|
-
exports.extractIpAddress = extractIpAddress;
|
6
|
-
const zod_1 = require("zod");
|
7
|
-
exports.deviceDetailsSchema = zod_1.z.object({
|
8
|
-
userAgent: zod_1.z.string().nullable(),
|
9
|
-
ipAddress: zod_1.z.string(),
|
10
|
-
});
|
11
|
-
function extractDeviceDetails(req, trustProxy) {
|
12
|
-
const userAgent = req.headers['user-agent'] || null;
|
13
|
-
const ipAddress = extractIpAddress(req, trustProxy) || null;
|
14
|
-
if (!ipAddress) {
|
15
|
-
throw new Error('Could not determine IP address');
|
16
|
-
}
|
17
|
-
return { userAgent, ipAddress };
|
18
|
-
}
|
19
|
-
function extractIpAddress(req, trustProxy) {
|
20
|
-
// Express app compatibility
|
21
|
-
if ('ip' in req && typeof req.ip === 'string') {
|
22
|
-
return req.ip;
|
23
|
-
}
|
24
|
-
if (trustProxy) {
|
25
|
-
const forwardedFor = req.headers['x-forwarded-for'];
|
26
|
-
if (typeof forwardedFor === 'string') {
|
27
|
-
const firstForward = forwardedFor.split(',')[0].trim();
|
28
|
-
if (firstForward)
|
29
|
-
return firstForward;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
return req.socket.remoteAddress;
|
33
|
-
}
|
34
|
-
//# sourceMappingURL=device-details.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"device-details.js","sourceRoot":"","sources":["../../src/device/device-details.ts"],"names":[],"mappings":";;;AAUA,oDAYC;AAED,4CAkBC;AAxCD,6BAAuB;AAEV,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1C,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAA;AAGF,SAAgB,oBAAoB,CAClC,GAAoB,EACpB,UAAmB;IAEnB,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,IAAI,CAAA;IACnD,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,IAAI,CAAA;IAE3D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;IACnD,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAA;AACjC,CAAC;AAED,SAAgB,gBAAgB,CAC9B,GAAoB,EACpB,UAAmB;IAEnB,4BAA4B;IAC5B,IAAI,IAAI,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QAC9C,OAAO,GAAG,CAAC,EAAE,CAAA;IACf,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;QACnD,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAA;YACvD,IAAI,YAAY;gBAAE,OAAO,YAAY,CAAA;QACvC,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,CAAA;AACjC,CAAC"}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { IncomingMessage } from 'node:http'
|
2
|
-
|
3
|
-
import { z } from 'zod'
|
4
|
-
|
5
|
-
export const deviceDetailsSchema = z.object({
|
6
|
-
userAgent: z.string().nullable(),
|
7
|
-
ipAddress: z.string(),
|
8
|
-
})
|
9
|
-
export type DeviceDetails = z.infer<typeof deviceDetailsSchema>
|
10
|
-
|
11
|
-
export function extractDeviceDetails(
|
12
|
-
req: IncomingMessage,
|
13
|
-
trustProxy: boolean,
|
14
|
-
): DeviceDetails {
|
15
|
-
const userAgent = req.headers['user-agent'] || null
|
16
|
-
const ipAddress = extractIpAddress(req, trustProxy) || null
|
17
|
-
|
18
|
-
if (!ipAddress) {
|
19
|
-
throw new Error('Could not determine IP address')
|
20
|
-
}
|
21
|
-
|
22
|
-
return { userAgent, ipAddress }
|
23
|
-
}
|
24
|
-
|
25
|
-
export function extractIpAddress(
|
26
|
-
req: IncomingMessage,
|
27
|
-
trustProxy: boolean,
|
28
|
-
): string | undefined {
|
29
|
-
// Express app compatibility
|
30
|
-
if ('ip' in req && typeof req.ip === 'string') {
|
31
|
-
return req.ip
|
32
|
-
}
|
33
|
-
|
34
|
-
if (trustProxy) {
|
35
|
-
const forwardedFor = req.headers['x-forwarded-for']
|
36
|
-
if (typeof forwardedFor === 'string') {
|
37
|
-
const firstForward = forwardedFor.split(',')[0]!.trim()
|
38
|
-
if (firstForward) return firstForward
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
return req.socket.remoteAddress
|
43
|
-
}
|