@atproto/oauth-client 0.1.0 → 0.1.2-rc.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +23 -0
- package/README.md +165 -31
- package/dist/errors/token-invalid-error.d.ts +7 -0
- package/dist/errors/token-invalid-error.d.ts.map +1 -0
- package/dist/errors/token-invalid-error.js +16 -0
- package/dist/errors/token-invalid-error.js.map +1 -0
- package/dist/errors/token-refresh-error.d.ts +7 -0
- package/dist/errors/token-refresh-error.d.ts.map +1 -0
- package/dist/errors/token-refresh-error.js +16 -0
- package/dist/errors/token-refresh-error.js.map +1 -0
- package/dist/errors/token-revoked-error.d.ts +7 -0
- package/dist/errors/token-revoked-error.d.ts.map +1 -0
- package/dist/errors/token-revoked-error.js +16 -0
- package/dist/errors/token-revoked-error.js.map +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/lock.d.ts +2 -1
- package/dist/lock.d.ts.map +1 -1
- package/dist/lock.js +2 -2
- package/dist/lock.js.map +1 -1
- package/dist/oauth-agent.d.ts.map +1 -1
- package/dist/oauth-agent.js +14 -9
- package/dist/oauth-agent.js.map +1 -1
- package/dist/oauth-atp-agent.d.ts +11 -0
- package/dist/oauth-atp-agent.d.ts.map +1 -0
- package/dist/oauth-atp-agent.js +52 -0
- package/dist/oauth-atp-agent.js.map +1 -0
- package/dist/oauth-client.d.ts +254 -24
- package/dist/oauth-client.d.ts.map +1 -1
- package/dist/oauth-client.js +68 -9
- package/dist/oauth-client.js.map +1 -1
- package/dist/oauth-resolver.d.ts +5 -4
- package/dist/oauth-resolver.d.ts.map +1 -1
- package/dist/oauth-resolver.js.map +1 -1
- package/dist/oauth-server-agent.d.ts.map +1 -1
- package/dist/oauth-server-agent.js +85 -29
- package/dist/oauth-server-agent.js.map +1 -1
- package/dist/runtime-implementation.d.ts +10 -5
- package/dist/runtime-implementation.d.ts.map +1 -1
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +18 -12
- package/dist/runtime.js.map +1 -1
- package/dist/session-getter.d.ts +19 -0
- package/dist/session-getter.d.ts.map +1 -1
- package/dist/session-getter.js +134 -42
- package/dist/session-getter.js.map +1 -1
- package/dist/state-store.d.ts +11 -0
- package/dist/state-store.d.ts.map +1 -0
- package/dist/state-store.js +3 -0
- package/dist/state-store.js.map +1 -0
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +10 -3
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +43 -23
- package/dist/util.js.map +1 -1
- package/dist/validate-client-metadata.d.ts.map +1 -1
- package/dist/validate-client-metadata.js +17 -0
- package/dist/validate-client-metadata.js.map +1 -1
- package/package.json +10 -8
- package/src/errors/token-invalid-error.ts +9 -0
- package/src/{refresh-error.ts → errors/token-refresh-error.ts} +1 -1
- package/src/errors/token-revoked-error.ts +9 -0
- package/src/index.ts +12 -1
- package/src/lock.ts +3 -4
- package/src/oauth-agent.ts +20 -9
- package/src/oauth-atp-agent.ts +49 -0
- package/src/oauth-client.ts +117 -34
- package/src/oauth-resolver.ts +4 -4
- package/src/oauth-server-agent.ts +9 -9
- package/src/runtime-implementation.ts +19 -11
- package/src/runtime.ts +13 -17
- package/src/session-getter.ts +135 -71
- package/src/state-store.ts +12 -0
- package/src/types.ts +5 -2
- package/src/util.ts +63 -32
- package/src/validate-client-metadata.ts +18 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"session-getter.js","sourceRoot":"","sources":["../src/session-getter.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"session-getter.js","sourceRoot":"","sources":["../src/session-getter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAImC;AAGnC,4EAAmE;AACnE,4EAAmE;AACnE,4EAAmE;AACnE,uEAA8D;AAI9D,uCAA4D;AAu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;YACjC,uDAAuD;YACvD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;QAC9D,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,OAA0B;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,yBAAyB,GAAG,EAAE,EAAE,KAAK,IAAI,EAAE;;;gBACvE,yEAAyE;gBACzE,8CAA8C;gBAC9C,MAAM,MAAM,kCAAG,IAAA,uBAAa,EAAC,IAAI,EAAE,OAAO,CAAC,QAAA,CAAA;gBAE3C,OAAO,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;;;;;;;;;SACpD,CAAC,CAAA;IACJ,CAAC;CACF;AAzMD,sCAyMC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { SimpleStore } from '@atproto-labs/simple-store';
|
2
|
+
import { Key } from '@atproto/jwk';
|
3
|
+
export type InternalStateData = {
|
4
|
+
iss: string;
|
5
|
+
nonce: string;
|
6
|
+
dpopKey: Key;
|
7
|
+
verifier?: string;
|
8
|
+
appState?: string;
|
9
|
+
};
|
10
|
+
export type StateStore = SimpleStore<string, InternalStateData>;
|
11
|
+
//# sourceMappingURL=state-store.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"state-store.d.ts","sourceRoot":"","sources":["../src/state-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAElC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,GAAG,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"state-store.js","sourceRoot":"","sources":["../src/state-store.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
CHANGED
@@ -2,12 +2,13 @@ import z from 'zod';
|
|
2
2
|
export type AuthorizeOptions = {
|
3
3
|
display?: 'page' | 'popup' | 'touch' | 'wap';
|
4
4
|
redirect_uri?: string;
|
5
|
-
id_token_hint?: string;
|
6
|
-
max_age?: number;
|
7
5
|
prompt?: 'login' | 'none' | 'consent' | 'select_account';
|
8
6
|
scope?: string;
|
9
7
|
state?: string;
|
8
|
+
signal?: AbortSignal;
|
10
9
|
ui_locales?: string;
|
10
|
+
id_token_hint?: string;
|
11
|
+
max_age?: number;
|
11
12
|
};
|
12
13
|
export declare const clientMetadataSchema: z.ZodObject<z.objectUtil.extendShape<{
|
13
14
|
redirect_uris: z.ZodArray<z.ZodString, "atleastone">;
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,CAAC,MAAM,KAAK,CAAA;AAMnB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAA;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,CAAC,MAAM,KAAK,CAAA;AAMnB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAA;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,CAAC,EAAE,OAAO,GAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE/B,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
|
package/dist/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,sDAG6B;
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,sDAG6B;AAqBhB,QAAA,oBAAoB,GAAG,uCAAyB,CAAC,MAAM,CAAC;IACnE,SAAS,EAAE,iCAAmB,CAAC,GAAG,EAAE;CACrC,CAAC,CAAA"}
|
package/dist/util.d.ts
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
export type Awaitable<T> = T | PromiseLike<T>;
|
1
3
|
/**
|
2
4
|
* @todo (?) move to common package
|
3
5
|
*/
|
4
|
-
export declare const
|
6
|
+
export declare const timeoutSignal: (timeout: number, options?: {
|
5
7
|
signal?: AbortSignal;
|
6
|
-
|
7
|
-
}, fn: (signal: AbortSignal) => T | PromiseLike<T>) => Promise<T>;
|
8
|
+
}) => AbortSignal & Disposable;
|
8
9
|
export declare function contentMime(headers: Headers): string | undefined;
|
10
|
+
export declare class CustomEventTarget<EventDetailMap extends Record<string, unknown>> {
|
11
|
+
readonly eventTarget: EventTarget;
|
12
|
+
addEventListener<T extends Extract<keyof EventDetailMap, string>>(type: T, callback: (event: CustomEvent<EventDetailMap[T]>) => void, options?: AddEventListenerOptions | boolean): void;
|
13
|
+
removeEventListener<T extends Extract<keyof EventDetailMap, string>>(type: T, callback: (event: CustomEvent<EventDetailMap[T]>) => void, options?: EventListenerOptions | boolean): void;
|
14
|
+
dispatchCustomEvent<T extends Extract<keyof EventDetailMap, string>>(type: T, detail: EventDetailMap[T]): boolean;
|
15
|
+
}
|
9
16
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;AAK7C;;GAEG;AACH,eAAO,MAAM,aAAa,YACf,MAAM,YACL;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,KACjC,WAAW,GAAG,UAmChB,CAAA;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAEhE;AAED,qBAAa,iBAAiB,CAAC,cAAc,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3E,QAAQ,CAAC,WAAW,cAAoB;IAExC,gBAAgB,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,cAAc,EAAE,MAAM,CAAC,EAC9D,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EACzD,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,GAC1C,IAAI;IAIP,mBAAmB,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,cAAc,EAAE,MAAM,CAAC,EACjE,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EACzD,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,GACvC,IAAI;IAQP,mBAAmB,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,cAAc,EAAE,MAAM,CAAC,EACjE,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GACxB,OAAO;CAGX"}
|
package/dist/util.js
CHANGED
@@ -1,35 +1,55 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.contentMime = exports.
|
3
|
+
exports.CustomEventTarget = exports.contentMime = exports.timeoutSignal = void 0;
|
4
|
+
// @ts-expect-error
|
5
|
+
Symbol.dispose ?? (Symbol.dispose = Symbol('@@dispose'));
|
4
6
|
/**
|
5
7
|
* @todo (?) move to common package
|
6
8
|
*/
|
7
|
-
const
|
8
|
-
|
9
|
-
|
10
|
-
const { signal } = abortController;
|
11
|
-
options?.signal?.addEventListener('abort', (reason) => abortController.abort(reason), { once: true, signal });
|
12
|
-
if (options?.timeout != null) {
|
13
|
-
const timeoutId = setTimeout((err) => abortController.abort(err), options.timeout, new Error('Timeout'));
|
14
|
-
timeoutId.unref?.(); // NodeJS only
|
15
|
-
signal.addEventListener('abort', () => clearTimeout(timeoutId), {
|
16
|
-
once: true,
|
17
|
-
signal,
|
18
|
-
});
|
19
|
-
}
|
20
|
-
try {
|
21
|
-
return await fn(signal);
|
22
|
-
}
|
23
|
-
finally {
|
24
|
-
// - Remove listener on incoming signal
|
25
|
-
// - Cancel timeout
|
26
|
-
// - Cancel pending (async) tasks
|
27
|
-
abortController.abort();
|
9
|
+
const timeoutSignal = (timeout, options) => {
|
10
|
+
if (!Number.isInteger(timeout) || timeout < 0) {
|
11
|
+
throw new TypeError('Expected a positive integer');
|
28
12
|
}
|
13
|
+
options?.signal?.throwIfAborted();
|
14
|
+
const controller = new AbortController();
|
15
|
+
const { signal } = controller;
|
16
|
+
options?.signal?.addEventListener('abort', (reason) => controller.abort(reason), { once: true, signal });
|
17
|
+
const timeoutId = setTimeout((err) => controller.abort(err), timeout,
|
18
|
+
// create Error here to keep original stack trace
|
19
|
+
new Error('Timeout'));
|
20
|
+
timeoutId?.unref?.(); // NodeJS only
|
21
|
+
signal.addEventListener('abort', () => clearTimeout(timeoutId), {
|
22
|
+
once: true,
|
23
|
+
signal,
|
24
|
+
});
|
25
|
+
Object.defineProperty(signal, Symbol.dispose, {
|
26
|
+
value: () => controller.abort(),
|
27
|
+
});
|
28
|
+
return signal;
|
29
29
|
};
|
30
|
-
exports.
|
30
|
+
exports.timeoutSignal = timeoutSignal;
|
31
31
|
function contentMime(headers) {
|
32
32
|
return headers.get('content-type')?.split(';')[0].trim();
|
33
33
|
}
|
34
34
|
exports.contentMime = contentMime;
|
35
|
+
class CustomEventTarget {
|
36
|
+
constructor() {
|
37
|
+
Object.defineProperty(this, "eventTarget", {
|
38
|
+
enumerable: true,
|
39
|
+
configurable: true,
|
40
|
+
writable: true,
|
41
|
+
value: new EventTarget()
|
42
|
+
});
|
43
|
+
}
|
44
|
+
addEventListener(type, callback, options) {
|
45
|
+
this.eventTarget.addEventListener(type, callback, options);
|
46
|
+
}
|
47
|
+
removeEventListener(type, callback, options) {
|
48
|
+
this.eventTarget.removeEventListener(type, callback, options);
|
49
|
+
}
|
50
|
+
dispatchCustomEvent(type, detail) {
|
51
|
+
return this.eventTarget.dispatchEvent(new CustomEvent(type, { detail }));
|
52
|
+
}
|
53
|
+
}
|
54
|
+
exports.CustomEventTarget = CustomEventTarget;
|
35
55
|
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAEA,mBAAmB;AACnB,MAAM,CAAC,OAAO,KAAd,MAAM,CAAC,OAAO,GAAK,MAAM,CAAC,WAAW,CAAC,EAAA;AAEtC;;GAEG;AACI,MAAM,aAAa,GAAG,CAC3B,OAAe,EACf,OAAkC,EACR,EAAE;IAC5B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAA;IACpD,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;IAEjC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;IACxC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAA;IAE7B,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAC/B,OAAO,EACP,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC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AED,mBAAmB,CACjB,IAAO,EACP,MAAyB;QAEzB,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;IAC1E,CAAC;CACF;AA7BD,8CA6BC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validate-client-metadata.d.ts","sourceRoot":"","sources":["../src/validate-client-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAEL,wBAAwB,EACzB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAA;AAQjE,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,wBAAwB,EAC/B,MAAM,CAAC,EAAE,MAAM,GACd,cAAc,
|
1
|
+
{"version":3,"file":"validate-client-metadata.d.ts","sourceRoot":"","sources":["../src/validate-client-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAEL,wBAAwB,EACzB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAA;AAQjE,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,wBAAwB,EAC/B,MAAM,CAAC,EAAE,MAAM,GACd,cAAc,CA6DhB"}
|
@@ -8,6 +8,23 @@ const _ENDPOINT_AUTH_METHOD = '_endpoint_auth_method';
|
|
8
8
|
const _ENDPOINT_AUTH_SIGNING_ALG = '_endpoint_auth_signing_alg';
|
9
9
|
const TOKEN_ENDPOINT_AUTH_METHOD = `token${_ENDPOINT_AUTH_METHOD}`;
|
10
10
|
function validateClientMetadata(input, keyset) {
|
11
|
+
if (input.jwks) {
|
12
|
+
if (!keyset) {
|
13
|
+
throw new TypeError(`Keyset must not be provided when jwks is provided`);
|
14
|
+
}
|
15
|
+
for (const key of input.jwks.keys) {
|
16
|
+
if (!key.kid) {
|
17
|
+
throw new TypeError(`Key must have a "kid" property`);
|
18
|
+
}
|
19
|
+
else if (!keyset.has(key.kid)) {
|
20
|
+
throw new TypeError(`Key with kid "${key.kid}" not found in keyset`);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
// Allow to pass a keyset and omit the jwks/jwks_uri properties
|
25
|
+
if (!input.jwks && !input.jwks_uri && keyset?.size) {
|
26
|
+
input = { ...input, jwks: keyset.toJSON() };
|
27
|
+
}
|
11
28
|
const metadata = types_js_1.clientMetadataSchema.parse(input);
|
12
29
|
// ATPROTO uses client metadata discovery
|
13
30
|
try {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validate-client-metadata.js","sourceRoot":"","sources":["../src/validate-client-metadata.ts"],"names":[],"mappings":";;;AACA,sDAG6B;AAE7B,yCAAiE;AAEjE,6CAA6C;AAC7C,MAAM,qBAAqB,GAAG,uBAAuB,CAAA;AACrD,MAAM,0BAA0B,GAAG,4BAA4B,CAAA;AAE/D,MAAM,0BAA0B,GAAG,QAAQ,qBAAqB,EAAE,CAAA;AAElE,SAAgB,sBAAsB,CACpC,KAA+B,EAC/B,MAAe;IAEf,MAAM,QAAQ,GAAG,+BAAoB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAElD,yCAAyC;IACzC,IAAI,CAAC;QACH,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,SAAS,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IACjE,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,0BAA0B,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,SAAS,CAAC,GAAG,0BAA0B,mBAAmB,CAAC,CAAA;IACvE,CAAC;IAED,KAAK,MAAM,YAAY,IAAI,gDAAkC,EAAE,CAAC;QAC9D,MAAM,MAAM,GAA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,QAAQ,CAAC,GAAG,YAAY,GAAG,0BAA0B,EAAE,CAAC,EAAE,CAAC;oBAC7D,MAAM,IAAI,SAAS,CACjB,GAAG,YAAY,GAAG,0BAA0B,uBAAuB,CACpE,CAAA;gBACH,CAAC;gBACD,MAAK;YACP,KAAK,mBAAmB;gBACtB,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,MAAM,IAAI,SAAS,CAAC,0BAA0B,MAAM,SAAS,CAAC,CAAA;gBAChE,CAAC;gBACD,IAAI,CAAC,QAAQ,CAAC,GAAG,YAAY,GAAG,0BAA0B,EAAE,CAAC,EAAE,CAAC;oBAC9D,MAAM,IAAI,SAAS,CACjB,GAAG,YAAY,GAAG,0BAA0B,mBAAmB,CAChE,CAAA;gBACH,CAAC;gBACD,MAAK;YACP;gBACE,MAAM,IAAI,SAAS,CACjB,YAAY,YAAY,GAAG,qBAAqB,YAAY,MAAM,EAAE,CACrE,CAAA;QACL,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC;AAhED,wDAgEC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atproto/oauth-client",
|
3
|
-
"version": "0.1.0",
|
3
|
+
"version": "0.1.2-rc.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "OAuth client for ATPROTO PDS. This package serves as common base for environment-specific implementations (NodeJS, Browser, React-Native).",
|
6
6
|
"keywords": [
|
@@ -27,15 +27,17 @@
|
|
27
27
|
"dependencies": {
|
28
28
|
"multiformats": "^9.9.0",
|
29
29
|
"zod": "^3.23.8",
|
30
|
-
"@atproto-labs/did-resolver": "0.1.
|
30
|
+
"@atproto-labs/did-resolver": "0.1.1",
|
31
31
|
"@atproto-labs/fetch": "0.1.0",
|
32
|
-
"@atproto-labs/
|
33
|
-
"@atproto-labs/
|
34
|
-
"@atproto-labs/simple-store": "0.1.
|
35
|
-
"@atproto-labs/simple-store-memory": "0.1.
|
32
|
+
"@atproto-labs/identity-resolver": "0.1.1",
|
33
|
+
"@atproto-labs/handle-resolver": "0.1.1",
|
34
|
+
"@atproto-labs/simple-store": "0.1.1",
|
35
|
+
"@atproto-labs/simple-store-memory": "0.1.1",
|
36
|
+
"@atproto/api": "0.13.0-rc.0",
|
37
|
+
"@atproto/jwk": "0.1.1",
|
36
38
|
"@atproto/did": "0.1.0",
|
37
|
-
"@atproto/
|
38
|
-
"@atproto/oauth-types": "0.1.
|
39
|
+
"@atproto/xrpc": "0.6.0-rc.0",
|
40
|
+
"@atproto/oauth-types": "0.1.1"
|
39
41
|
},
|
40
42
|
"devDependencies": {
|
41
43
|
"typescript": "^5.3.3"
|
package/src/index.ts
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
+
export * from '@atproto-labs/did-resolver'
|
1
2
|
export {
|
2
3
|
FetchError,
|
3
4
|
FetchRequestError,
|
4
5
|
FetchResponseError,
|
5
6
|
} from '@atproto-labs/fetch'
|
7
|
+
export * from '@atproto-labs/handle-resolver'
|
8
|
+
|
9
|
+
export * from '@atproto/did'
|
10
|
+
export * from '@atproto/oauth-types'
|
11
|
+
|
6
12
|
export * from './oauth-agent.js'
|
13
|
+
export * from './oauth-atp-agent.js'
|
7
14
|
export * from './oauth-authorization-server-metadata-resolver.js'
|
8
15
|
export * from './oauth-callback-error.js'
|
9
16
|
export * from './oauth-client.js'
|
@@ -12,7 +19,11 @@ export * from './oauth-resolver-error.js'
|
|
12
19
|
export * from './oauth-response-error.js'
|
13
20
|
export * from './oauth-server-agent.js'
|
14
21
|
export * from './oauth-server-factory.js'
|
15
|
-
export * from './refresh-error.js'
|
16
22
|
export * from './runtime-implementation.js'
|
17
23
|
export * from './session-getter.js'
|
24
|
+
export * from './state-store.js'
|
18
25
|
export * from './types.js'
|
26
|
+
|
27
|
+
export * from './errors/token-invalid-error.js'
|
28
|
+
export * from './errors/token-refresh-error.js'
|
29
|
+
export * from './errors/token-revoked-error.js'
|
package/src/lock.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { RuntimeLock } from './runtime-implementation.js'
|
2
|
+
|
1
3
|
const locks = new Map<unknown, Promise<void>>()
|
2
4
|
|
3
5
|
function acquireLocalLock(name: unknown): Promise<() => void> {
|
@@ -20,10 +22,7 @@ function acquireLocalLock(name: unknown): Promise<() => void> {
|
|
20
22
|
})
|
21
23
|
}
|
22
24
|
|
23
|
-
export
|
24
|
-
name: string,
|
25
|
-
fn: () => T | PromiseLike<T>,
|
26
|
-
): Promise<T> {
|
25
|
+
export const requestLocalLock: RuntimeLock = (name, fn) => {
|
27
26
|
return acquireLocalLock(name).then(async (release) => {
|
28
27
|
try {
|
29
28
|
return await fn()
|
package/src/oauth-agent.ts
CHANGED
@@ -2,6 +2,8 @@ import { Fetch, bindFetch } from '@atproto-labs/fetch'
|
|
2
2
|
import { JwtPayload, unsafeDecodeJwt } from '@atproto/jwk'
|
3
3
|
import { OAuthAuthorizationServerMetadata } from '@atproto/oauth-types'
|
4
4
|
|
5
|
+
import { TokenInvalidError } from './errors/token-invalid-error.js'
|
6
|
+
import { TokenRevokedError } from './errors/token-revoked-error.js'
|
5
7
|
import { dpopFetchWrapper } from './fetch-dpop.js'
|
6
8
|
import { OAuthServerAgent, TokenSet } from './oauth-server-agent.js'
|
7
9
|
import { SessionGetter } from './session-getter.js'
|
@@ -76,7 +78,10 @@ export class OAuthAgent {
|
|
76
78
|
const { tokenSet } = await this.sessionGetter.getSession(this.sub, false)
|
77
79
|
await this.server.revoke(tokenSet.access_token)
|
78
80
|
} finally {
|
79
|
-
await this.sessionGetter.delStored(
|
81
|
+
await this.sessionGetter.delStored(
|
82
|
+
this.sub,
|
83
|
+
new TokenRevokedError(this.sub),
|
84
|
+
)
|
80
85
|
}
|
81
86
|
}
|
82
87
|
|
@@ -96,13 +101,13 @@ export class OAuthAgent {
|
|
96
101
|
})
|
97
102
|
|
98
103
|
// If the token is not expired, we don't need to refresh it
|
99
|
-
if (!
|
104
|
+
if (!isInvalidTokenResponse(initialResponse)) {
|
100
105
|
return initialResponse
|
101
106
|
}
|
102
107
|
|
103
108
|
let tokenSetFresh: TokenSet
|
104
109
|
try {
|
105
|
-
//
|
110
|
+
// Force a refresh
|
106
111
|
tokenSetFresh = await this.getTokenSet(true)
|
107
112
|
} catch (err) {
|
108
113
|
return initialResponse
|
@@ -123,12 +128,18 @@ export class OAuthAgent {
|
|
123
128
|
|
124
129
|
const finalResponse = await this.dpopFetch(finalUrl, { ...init, headers })
|
125
130
|
|
126
|
-
//
|
127
|
-
//
|
128
|
-
|
131
|
+
// The token was successfully refreshed, but is still not accepted by the
|
132
|
+
// resource server. This might be due to the resource server not accepting
|
133
|
+
// credentials from the authorization server (e.g. because some migration
|
134
|
+
// occurred). Any ways, there is no point in keeping the session.
|
135
|
+
if (isInvalidTokenResponse(finalResponse)) {
|
129
136
|
// TODO: Is there a "softer" way to handle this, e.g. by marking the
|
130
|
-
// session as "expired"
|
131
|
-
|
137
|
+
// session as "expired" in the session store, allowing the user to trigger
|
138
|
+
// a new login (using login_hint/id_token_hint)?
|
139
|
+
await this.sessionGetter.delStored(
|
140
|
+
this.sub,
|
141
|
+
new TokenInvalidError(this.sub),
|
142
|
+
)
|
132
143
|
}
|
133
144
|
|
134
145
|
return finalResponse
|
@@ -139,7 +150,7 @@ export class OAuthAgent {
|
|
139
150
|
* @see {@link https://datatracker.ietf.org/doc/html/rfc6750#section-3}
|
140
151
|
* @see {@link https://datatracker.ietf.org/doc/html/rfc9449#name-resource-server-provided-no}
|
141
152
|
*/
|
142
|
-
function
|
153
|
+
function isInvalidTokenResponse(response: Response) {
|
143
154
|
if (response.status !== 401) return false
|
144
155
|
const wwwAuth = response.headers.get('WWW-Authenticate')
|
145
156
|
return (
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { Agent } from '@atproto/api'
|
2
|
+
import { XRPCError } from '@atproto/xrpc'
|
3
|
+
import { FetchError, FetchResponseError } from '@atproto-labs/fetch'
|
4
|
+
|
5
|
+
import { OAuthAgent } from './oauth-agent.js'
|
6
|
+
|
7
|
+
export class OAuthAtpAgent extends Agent {
|
8
|
+
constructor(readonly oauthAgent: OAuthAgent) {
|
9
|
+
super(async (url, init) => {
|
10
|
+
try {
|
11
|
+
return await this.oauthAgent.request(url, init)
|
12
|
+
} catch (cause) {
|
13
|
+
if (cause instanceof FetchError) {
|
14
|
+
const { statusCode, message } = cause
|
15
|
+
throw new XRPCError(statusCode, undefined, message, undefined, {
|
16
|
+
cause,
|
17
|
+
})
|
18
|
+
}
|
19
|
+
|
20
|
+
if (cause instanceof FetchResponseError) {
|
21
|
+
const { statusCode, message, response } = cause
|
22
|
+
const headers = Object.fromEntries(response.headers.entries())
|
23
|
+
throw new XRPCError(statusCode, undefined, message, headers, {
|
24
|
+
cause,
|
25
|
+
})
|
26
|
+
}
|
27
|
+
|
28
|
+
throw cause
|
29
|
+
}
|
30
|
+
})
|
31
|
+
}
|
32
|
+
|
33
|
+
clone(): this {
|
34
|
+
const agent = new OAuthAtpAgent(this.oauthAgent) as this
|
35
|
+
return this.copyInto(agent)
|
36
|
+
}
|
37
|
+
|
38
|
+
get did(): string {
|
39
|
+
return this.oauthAgent.sub
|
40
|
+
}
|
41
|
+
|
42
|
+
async signOut() {
|
43
|
+
await this.oauthAgent.signOut()
|
44
|
+
}
|
45
|
+
|
46
|
+
public async refreshIfNeeded(): Promise<void> {
|
47
|
+
await this.oauthAgent.refreshIfNeeded()
|
48
|
+
}
|
49
|
+
}
|