@atproto/oauth-client 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +42 -0
- package/README.md +12 -6
- package/dist/atproto-token-response.d.ts +110 -0
- package/dist/atproto-token-response.d.ts.map +1 -0
- package/dist/atproto-token-response.js +20 -0
- package/dist/atproto-token-response.js.map +1 -0
- package/dist/fetch-dpop.js +1 -2
- package/dist/fetch-dpop.js.map +1 -1
- package/dist/oauth-authorization-server-metadata-resolver.d.ts +6 -2
- package/dist/oauth-authorization-server-metadata-resolver.d.ts.map +1 -1
- package/dist/oauth-authorization-server-metadata-resolver.js +18 -9
- package/dist/oauth-authorization-server-metadata-resolver.js.map +1 -1
- package/dist/oauth-callback-error.d.ts.map +1 -1
- package/dist/oauth-client.d.ts +30 -15
- package/dist/oauth-client.d.ts.map +1 -1
- package/dist/oauth-client.js +24 -17
- package/dist/oauth-client.js.map +1 -1
- package/dist/oauth-protected-resource-metadata-resolver.d.ts +5 -1
- package/dist/oauth-protected-resource-metadata-resolver.d.ts.map +1 -1
- package/dist/oauth-protected-resource-metadata-resolver.js +18 -11
- package/dist/oauth-protected-resource-metadata-resolver.js.map +1 -1
- package/dist/oauth-resolver.d.ts +2 -2
- package/dist/oauth-server-agent.d.ts +15 -12
- package/dist/oauth-server-agent.d.ts.map +1 -1
- package/dist/oauth-server-agent.js +66 -47
- package/dist/oauth-server-agent.js.map +1 -1
- package/dist/oauth-session.d.ts +13 -8
- package/dist/oauth-session.d.ts.map +1 -1
- package/dist/oauth-session.js +12 -7
- package/dist/oauth-session.js.map +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js.map +1 -1
- package/dist/session-getter.d.ts +5 -4
- package/dist/session-getter.d.ts.map +1 -1
- package/dist/session-getter.js +52 -32
- package/dist/session-getter.js.map +1 -1
- package/dist/types.d.ts +98 -102
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +6 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +56 -2
- package/dist/util.js.map +1 -1
- package/dist/validate-client-metadata.d.ts.map +1 -1
- package/dist/validate-client-metadata.js +17 -7
- package/dist/validate-client-metadata.js.map +1 -1
- package/package.json +9 -9
- package/src/atproto-token-response.ts +22 -0
- package/src/oauth-authorization-server-metadata-resolver.ts +22 -8
- package/src/oauth-client.ts +62 -32
- package/src/oauth-protected-resource-metadata-resolver.ts +22 -12
- package/src/oauth-server-agent.ts +89 -70
- package/src/oauth-session.ts +21 -13
- package/src/runtime.ts +1 -1
- package/src/session-getter.ts +53 -33
- package/src/types.ts +16 -11
- package/src/util.ts +78 -0
- package/src/validate-client-metadata.ts +23 -6
- package/tsconfig.build.tsbuildinfo +1 -0
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,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,gBAAgB,CAAA;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,WAAW,CAAA;IAGpB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC;eAAuC,CAAC;sBAA4C,CAAC;eAAqC,CAAC;;;eAA4E,CAAC;eAAqC,CAAC;eAAqC,CAAC;eAAsC,CAAC;mBAAgD,CAAC;eAAmI,CAAC;eAAuC,CAAC;sBAA4C,CAAC;eAAqC,CAAC;;;;;;;;;;;;;;;;;;;;;EAHrnqD,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,
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,sDAI6B;AAuBhB,QAAA,oBAAoB,GAAG,uCAAyB,CAAC,MAAM,CAAC;IACnE,SAAS,EAAE,iCAAmB,CAAC,GAAG,EAAE;CACrC,CAAC,CAAA"}
|
package/dist/util.d.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
/// <reference types="node" />
|
2
1
|
export type Awaitable<T> = T | PromiseLike<T>;
|
2
|
+
export type Simplify<T> = {
|
3
|
+
[K in keyof T]: T[K];
|
4
|
+
} & NonNullable<unknown>;
|
3
5
|
/**
|
4
6
|
* @todo (?) move to common package
|
5
7
|
*/
|
@@ -17,4 +19,7 @@ export declare class CustomEventTarget<EventDetailMap extends Record<string, unk
|
|
17
19
|
removeEventListener<T extends Extract<keyof EventDetailMap, string>>(type: T, callback: (event: CustomEvent<EventDetailMap[T]>) => void, options?: EventListenerOptions | boolean): void;
|
18
20
|
dispatchCustomEvent<T extends Extract<keyof EventDetailMap, string>>(type: T, detail: EventDetailMap[T], init?: EventInit): boolean;
|
19
21
|
}
|
22
|
+
export type SpaceSeparatedValue<Value extends string> = `${Value}` | `${Value} ${string}` | `${string} ${Value}` | `${string} ${Value} ${string}`;
|
23
|
+
export declare const includesSpaceSeparatedValue: <Value extends string>(input: string, value: Value) => input is SpaceSeparatedValue<Value>;
|
24
|
+
export declare function combineSignals(signals: readonly (AbortSignal | undefined)[]): AbortController & Disposable;
|
20
25
|
//# 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":"
|
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;AAC7C,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;AAKzE;;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;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,OAAO,UAAU,CAAC,WA4BtC,CAAA;AAEN,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,EACzB,IAAI,CAAC,EAAE,SAAS,GACf,OAAO;CAKX;AAED,MAAM,MAAM,mBAAmB,CAAC,KAAK,SAAS,MAAM,IAChD,GAAG,KAAK,EAAE,GACV,GAAG,KAAK,IAAI,MAAM,EAAE,GACpB,GAAG,MAAM,IAAI,KAAK,EAAE,GACpB,GAAG,MAAM,IAAI,KAAK,IAAI,MAAM,EAAE,CAAA;AAElC,eAAO,MAAM,2BAA2B,GAAI,KAAK,SAAS,MAAM,SACvD,MAAM,SACN,KAAK,KACX,KAAK,IAAI,mBAAmB,CAAC,KAAK,CA+BpC,CAAA;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,GAgCrD,eAAe,GAAG,UAAU,CAClD"}
|
package/dist/util.js
CHANGED
@@ -11,7 +11,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
12
12
|
};
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
14
|
-
exports.
|
14
|
+
exports.includesSpaceSeparatedValue = exports.CustomEventTarget = exports.CustomEvent = exports.timeoutSignal = void 0;
|
15
|
+
exports.contentMime = contentMime;
|
16
|
+
exports.combineSignals = combineSignals;
|
15
17
|
// @ts-expect-error
|
16
18
|
Symbol.dispose ?? (Symbol.dispose = Symbol('@@dispose'));
|
17
19
|
/**
|
@@ -42,7 +44,6 @@ exports.timeoutSignal = timeoutSignal;
|
|
42
44
|
function contentMime(headers) {
|
43
45
|
return headers.get('content-type')?.split(';')[0].trim();
|
44
46
|
}
|
45
|
-
exports.contentMime = contentMime;
|
46
47
|
/**
|
47
48
|
* Ponyfill for `CustomEvent` constructor.
|
48
49
|
*/
|
@@ -95,4 +96,57 @@ class CustomEventTarget {
|
|
95
96
|
}
|
96
97
|
}
|
97
98
|
exports.CustomEventTarget = CustomEventTarget;
|
99
|
+
const includesSpaceSeparatedValue = (input, value) => {
|
100
|
+
if (value.length === 0)
|
101
|
+
throw new TypeError('Value cannot be empty');
|
102
|
+
if (value.includes(' '))
|
103
|
+
throw new TypeError('Value cannot contain spaces');
|
104
|
+
// Optimized version of:
|
105
|
+
// return input.split(' ').includes(value)
|
106
|
+
const inputLength = input.length;
|
107
|
+
const valueLength = value.length;
|
108
|
+
if (inputLength < valueLength)
|
109
|
+
return false;
|
110
|
+
let idx = input.indexOf(value);
|
111
|
+
let idxEnd;
|
112
|
+
while (idx !== -1) {
|
113
|
+
idxEnd = idx + valueLength;
|
114
|
+
if (
|
115
|
+
// at beginning or preceded by space
|
116
|
+
(idx === 0 || input[idx - 1] === ' ') &&
|
117
|
+
// at end or followed by space
|
118
|
+
(idxEnd === inputLength || input[idxEnd] === ' ')) {
|
119
|
+
return true;
|
120
|
+
}
|
121
|
+
idx = input.indexOf(value, idxEnd + 1);
|
122
|
+
}
|
123
|
+
return false;
|
124
|
+
};
|
125
|
+
exports.includesSpaceSeparatedValue = includesSpaceSeparatedValue;
|
126
|
+
function combineSignals(signals) {
|
127
|
+
const controller = new AbortController();
|
128
|
+
const onAbort = function (_event) {
|
129
|
+
const reason = new Error('This operation was aborted', {
|
130
|
+
cause: this.reason,
|
131
|
+
});
|
132
|
+
controller.abort(reason);
|
133
|
+
};
|
134
|
+
for (const sig of signals) {
|
135
|
+
if (!sig)
|
136
|
+
continue;
|
137
|
+
if (sig.aborted) {
|
138
|
+
// Remove "abort" listener that was added to sig in previous iterations
|
139
|
+
controller.abort();
|
140
|
+
throw new Error('One of the signals is already aborted', {
|
141
|
+
cause: sig.reason,
|
142
|
+
});
|
143
|
+
}
|
144
|
+
sig.addEventListener('abort', onAbort, { signal: controller.signal });
|
145
|
+
}
|
146
|
+
controller[Symbol.dispose] = () => {
|
147
|
+
const reason = new Error('AbortController was disposed');
|
148
|
+
controller.abort(reason);
|
149
|
+
};
|
150
|
+
return controller;
|
151
|
+
}
|
98
152
|
//# 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":";;;;;;;;;;;;;;AAiDA,kCAEC;AA+GD,wCAiCC;AAhMD,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,MAAM,CAAC,EACpC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CACvB,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AAE;gBACvD,KAAK,EAAE,GAAG,CAAC,MAAM;aAClB,CAAC,CAAA;QACJ,CAAC;QAED,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAA;IACvE,CAAC;IAED,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,EAAE;QAChC,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;QAExD,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC1B,CAAC,CAAA;IAED,OAAO,UAA0C,CAAA;AACnD,CAAC"}
|
@@ -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,
|
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,EACL,wBAAwB,EAGzB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAA;AAKjE,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,wBAAwB,EAC/B,MAAM,CAAC,EAAE,MAAM,GACd,cAAc,CAuEhB"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.validateClientMetadata =
|
3
|
+
exports.validateClientMetadata = validateClientMetadata;
|
4
|
+
const oauth_types_1 = require("@atproto/oauth-types");
|
4
5
|
const types_js_1 = require("./types.js");
|
5
6
|
const TOKEN_ENDPOINT_AUTH_METHOD = `token_endpoint_auth_method`;
|
6
7
|
const TOKEN_ENDPOINT_AUTH_SIGNING_ALG = `token_endpoint_auth_signing_alg`;
|
@@ -23,12 +24,22 @@ function validateClientMetadata(input, keyset) {
|
|
23
24
|
input = { ...input, jwks: keyset.toJSON() };
|
24
25
|
}
|
25
26
|
const metadata = types_js_1.clientMetadataSchema.parse(input);
|
26
|
-
//
|
27
|
-
|
28
|
-
|
27
|
+
// Validate client ID
|
28
|
+
if (metadata.client_id.startsWith('http:')) {
|
29
|
+
(0, oauth_types_1.assertOAuthLoopbackClientId)(metadata.client_id);
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
(0, oauth_types_1.assertOAuthDiscoverableClientId)(metadata.client_id);
|
33
|
+
}
|
34
|
+
const scopes = metadata.scope?.split(' ');
|
35
|
+
if (!scopes?.includes('atproto')) {
|
36
|
+
throw new TypeError(`Client metadata must include the "atproto" scope`);
|
29
37
|
}
|
30
|
-
|
31
|
-
throw new TypeError(`
|
38
|
+
if (!metadata.response_types.includes('code')) {
|
39
|
+
throw new TypeError(`"response_types" must include "code"`);
|
40
|
+
}
|
41
|
+
if (!metadata.grant_types.includes('authorization_code')) {
|
42
|
+
throw new TypeError(`"grant_types" must include "authorization_code"`);
|
32
43
|
}
|
33
44
|
const method = metadata[TOKEN_ENDPOINT_AUTH_METHOD];
|
34
45
|
switch (method) {
|
@@ -52,5 +63,4 @@ function validateClientMetadata(input, keyset) {
|
|
52
63
|
}
|
53
64
|
return metadata;
|
54
65
|
}
|
55
|
-
exports.validateClientMetadata = validateClientMetadata;
|
56
66
|
//# sourceMappingURL=validate-client-metadata.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validate-client-metadata.js","sourceRoot":"","sources":["../src/validate-client-metadata.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"validate-client-metadata.js","sourceRoot":"","sources":["../src/validate-client-metadata.ts"],"names":[],"mappings":";;AAYA,wDA0EC;AArFD,sDAI6B;AAE7B,yCAAiE;AAEjE,MAAM,0BAA0B,GAAG,4BAA4B,CAAA;AAC/D,MA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
1
1
|
{
|
2
2
|
"name": "@atproto/oauth-client",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.3.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,19 +27,19 @@
|
|
27
27
|
"dependencies": {
|
28
28
|
"multiformats": "^9.9.0",
|
29
29
|
"zod": "^3.23.8",
|
30
|
-
"@atproto-labs/did-resolver": "0.1.
|
31
|
-
"@atproto-labs/fetch": "0.1.
|
32
|
-
"@atproto-labs/handle-resolver": "0.1.
|
33
|
-
"@atproto-labs/identity-resolver": "0.1.
|
30
|
+
"@atproto-labs/did-resolver": "0.1.5",
|
31
|
+
"@atproto-labs/fetch": "0.1.1",
|
32
|
+
"@atproto-labs/handle-resolver": "0.1.4",
|
33
|
+
"@atproto-labs/identity-resolver": "0.1.5",
|
34
34
|
"@atproto-labs/simple-store": "0.1.1",
|
35
35
|
"@atproto-labs/simple-store-memory": "0.1.1",
|
36
|
-
"@atproto/did": "0.1.
|
36
|
+
"@atproto/did": "0.1.3",
|
37
37
|
"@atproto/jwk": "0.1.1",
|
38
|
-
"@atproto/oauth-types": "0.
|
39
|
-
"@atproto/xrpc": "0.6.
|
38
|
+
"@atproto/oauth-types": "0.2.0",
|
39
|
+
"@atproto/xrpc": "0.6.3"
|
40
40
|
},
|
41
41
|
"devDependencies": {
|
42
|
-
"typescript": "^5.
|
42
|
+
"typescript": "^5.6.3"
|
43
43
|
},
|
44
44
|
"scripts": {
|
45
45
|
"build": "tsc --build tsconfig.build.json"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { atprotoDidSchema } from '@atproto/did'
|
2
|
+
import { oauthTokenResponseSchema } from '@atproto/oauth-types'
|
3
|
+
import { z } from 'zod'
|
4
|
+
|
5
|
+
import { includesSpaceSeparatedValue, SpaceSeparatedValue } from './util'
|
6
|
+
|
7
|
+
export type AtprotoScope = SpaceSeparatedValue<'atproto'>
|
8
|
+
export const isAtprotoScope = (input: string): input is AtprotoScope =>
|
9
|
+
includesSpaceSeparatedValue(input, 'atproto')
|
10
|
+
export const atprotoScopeSchema = z
|
11
|
+
.string()
|
12
|
+
.refine(isAtprotoScope, 'The "atproto" scope is required')
|
13
|
+
|
14
|
+
export const atprotoTokenResponseSchema = oauthTokenResponseSchema.extend({
|
15
|
+
token_type: z.literal('DPoP'),
|
16
|
+
sub: atprotoDidSchema,
|
17
|
+
scope: atprotoScopeSchema,
|
18
|
+
// OpenID is not compatible with atproto identities
|
19
|
+
id_token: z.never().optional(),
|
20
|
+
})
|
21
|
+
|
22
|
+
export type AtprotoTokenResponse = z.infer<typeof atprotoTokenResponseSchema>
|
@@ -14,7 +14,7 @@ import {
|
|
14
14
|
oauthAuthorizationServerMetadataValidator,
|
15
15
|
oauthIssuerIdentifierSchema,
|
16
16
|
} from '@atproto/oauth-types'
|
17
|
-
import { contentMime } from './util'
|
17
|
+
import { contentMime } from './util.js'
|
18
18
|
|
19
19
|
export type { GetCachedOptions, OAuthAuthorizationServerMetadata }
|
20
20
|
|
@@ -23,6 +23,10 @@ export type AuthorizationServerMetadataCache = SimpleStore<
|
|
23
23
|
OAuthAuthorizationServerMetadata
|
24
24
|
>
|
25
25
|
|
26
|
+
export type OAuthAuthorizationServerMetadataResolverConfig = {
|
27
|
+
allowHttpIssuer?: boolean
|
28
|
+
}
|
29
|
+
|
26
30
|
/**
|
27
31
|
* @see {@link https://datatracker.ietf.org/doc/html/rfc8414}
|
28
32
|
*/
|
@@ -31,31 +35,41 @@ export class OAuthAuthorizationServerMetadataResolver extends CachedGetter<
|
|
31
35
|
OAuthAuthorizationServerMetadata
|
32
36
|
> {
|
33
37
|
private readonly fetch: Fetch<unknown>
|
38
|
+
private readonly allowHttpIssuer: boolean
|
34
39
|
|
35
|
-
constructor(
|
40
|
+
constructor(
|
41
|
+
cache: AuthorizationServerMetadataCache,
|
42
|
+
fetch?: Fetch,
|
43
|
+
config?: OAuthAuthorizationServerMetadataResolverConfig,
|
44
|
+
) {
|
36
45
|
super(async (issuer, options) => this.fetchMetadata(issuer, options), cache)
|
37
46
|
|
38
47
|
this.fetch = bindFetch(fetch)
|
48
|
+
this.allowHttpIssuer = config?.allowHttpIssuer === true
|
39
49
|
}
|
40
50
|
|
41
51
|
async get(
|
42
|
-
|
52
|
+
input: string,
|
43
53
|
options?: GetCachedOptions,
|
44
54
|
): Promise<OAuthAuthorizationServerMetadata> {
|
45
|
-
|
55
|
+
const issuer = oauthIssuerIdentifierSchema.parse(input)
|
56
|
+
if (!this.allowHttpIssuer && issuer.startsWith('http:')) {
|
57
|
+
throw new TypeError(
|
58
|
+
'Unsecure issuer URL protocol only allowed in development and test environments',
|
59
|
+
)
|
60
|
+
}
|
61
|
+
return super.get(issuer, options)
|
46
62
|
}
|
47
63
|
|
48
64
|
private async fetchMetadata(
|
49
65
|
issuer: string,
|
50
66
|
options?: GetCachedOptions,
|
51
67
|
): Promise<OAuthAuthorizationServerMetadata> {
|
52
|
-
const headers = new Headers([['accept', 'application/json']])
|
53
|
-
if (options?.noCache) headers.set('cache-control', 'no-cache')
|
54
|
-
|
55
68
|
const url = new URL(`/.well-known/oauth-authorization-server`, issuer)
|
56
69
|
const request = new Request(url, {
|
70
|
+
headers: { accept: 'application/json' },
|
71
|
+
cache: options?.noCache ? 'no-cache' : undefined,
|
57
72
|
signal: options?.signal,
|
58
|
-
headers,
|
59
73
|
redirect: 'manual', // response must be 200 OK
|
60
74
|
})
|
61
75
|
|
package/src/oauth-client.ts
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
import {
|
2
|
+
assertAtprotoDid,
|
3
|
+
AtprotoDid,
|
2
4
|
DidCache,
|
3
5
|
DidResolverCached,
|
4
6
|
DidResolverCommon,
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
8
|
+
type DidResolverCommonOptions,
|
5
9
|
} from '@atproto-labs/did-resolver'
|
6
10
|
import { Fetch } from '@atproto-labs/fetch'
|
7
11
|
import {
|
@@ -14,6 +18,7 @@ import { IdentityResolver } from '@atproto-labs/identity-resolver'
|
|
14
18
|
import { SimpleStoreMemory } from '@atproto-labs/simple-store-memory'
|
15
19
|
import { Key, Keyset } from '@atproto/jwk'
|
16
20
|
import {
|
21
|
+
OAuthAuthorizationRequestParameters,
|
17
22
|
OAuthClientIdDiscoverable,
|
18
23
|
OAuthClientMetadata,
|
19
24
|
OAuthClientMetadataInput,
|
@@ -73,6 +78,21 @@ export type OAuthClientOptions = {
|
|
73
78
|
responseMode: OAuthResponseMode
|
74
79
|
clientMetadata: Readonly<OAuthClientMetadataInput>
|
75
80
|
keyset?: Keyset | Iterable<Key | undefined | null | false>
|
81
|
+
/**
|
82
|
+
* Determines if the client will allow communicating with the OAuth Servers
|
83
|
+
* (Authorization & Resource), or to retrieve "did:web" documents, over
|
84
|
+
* unsafe HTTP connections. It is recommended to set this to `true` only for
|
85
|
+
* development purposes.
|
86
|
+
*
|
87
|
+
* @note This does not affect the identity resolution mechanism, which will
|
88
|
+
* allow HTTP connections to the PLC Directory (if the provided directory url
|
89
|
+
* is "http:" based).
|
90
|
+
* @default false
|
91
|
+
* @see {@link OAuthProtectedResourceMetadataResolver.allowHttpResource}
|
92
|
+
* @see {@link OAuthAuthorizationServerMetadataResolver.allowHttpIssuer}
|
93
|
+
* @see {@link DidResolverCommonOptions.allowHttp}
|
94
|
+
*/
|
95
|
+
allowHttp?: boolean
|
76
96
|
|
77
97
|
// Stores
|
78
98
|
stateStore: StateStore
|
@@ -143,11 +163,12 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
143
163
|
readonly serverFactory: OAuthServerFactory
|
144
164
|
|
145
165
|
// Stores
|
146
|
-
readonly sessionGetter: SessionGetter
|
147
|
-
readonly stateStore: StateStore
|
166
|
+
protected readonly sessionGetter: SessionGetter
|
167
|
+
protected readonly stateStore: StateStore
|
148
168
|
|
149
169
|
constructor({
|
150
170
|
fetch = globalThis.fetch,
|
171
|
+
allowHttp = false,
|
151
172
|
|
152
173
|
stateStore,
|
153
174
|
sessionStore,
|
@@ -186,7 +207,7 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
186
207
|
this.oauthResolver = new OAuthResolver(
|
187
208
|
new IdentityResolver(
|
188
209
|
new DidResolverCached(
|
189
|
-
new DidResolverCommon({ fetch, plcDirectoryUrl }),
|
210
|
+
new DidResolverCommon({ fetch, plcDirectoryUrl, allowHttp }),
|
190
211
|
didCache,
|
191
212
|
),
|
192
213
|
new CachedHandleResolver(
|
@@ -197,10 +218,12 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
197
218
|
new OAuthProtectedResourceMetadataResolver(
|
198
219
|
protectedResourceMetadataCache,
|
199
220
|
fetch,
|
221
|
+
{ allowHttpResource: allowHttp },
|
200
222
|
),
|
201
223
|
new OAuthAuthorizationServerMetadataResolver(
|
202
224
|
authorizationServerMetadataCache,
|
203
225
|
fetch,
|
226
|
+
{ allowHttpIssuer: allowHttp },
|
204
227
|
),
|
205
228
|
)
|
206
229
|
this.serverFactory = new OAuthServerFactory(
|
@@ -248,7 +271,10 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
248
271
|
return this.keyset?.publicJwks ?? ({ keys: [] as const } as const)
|
249
272
|
}
|
250
273
|
|
251
|
-
async authorize(
|
274
|
+
async authorize(
|
275
|
+
input: string,
|
276
|
+
{ signal, ...options }: AuthorizeOptions = {},
|
277
|
+
): Promise<URL> {
|
252
278
|
const redirectUri =
|
253
279
|
options?.redirect_uri ?? this.clientMetadata.redirect_uris[0]
|
254
280
|
if (!this.clientMetadata.redirect_uris.includes(redirectUri)) {
|
@@ -256,10 +282,9 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
256
282
|
throw new TypeError('Invalid redirect_uri')
|
257
283
|
}
|
258
284
|
|
259
|
-
const { identity, metadata } = await this.oauthResolver.resolve(
|
260
|
-
|
261
|
-
|
262
|
-
)
|
285
|
+
const { identity, metadata } = await this.oauthResolver.resolve(input, {
|
286
|
+
signal,
|
287
|
+
})
|
263
288
|
|
264
289
|
const pkce = await this.runtime.generatePKCE()
|
265
290
|
const dpopKey = await this.runtime.generateKey(
|
@@ -275,7 +300,9 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
275
300
|
appState: options?.state,
|
276
301
|
})
|
277
302
|
|
278
|
-
const parameters = {
|
303
|
+
const parameters: OAuthAuthorizationRequestParameters = {
|
304
|
+
...options,
|
305
|
+
|
279
306
|
client_id: this.clientMetadata.client_id,
|
280
307
|
redirect_uri: redirectUri,
|
281
308
|
code_challenge: pkce.challenge,
|
@@ -285,16 +312,8 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
285
312
|
? input // If input is a handle or a DID, use it as a login_hint
|
286
313
|
: undefined,
|
287
314
|
response_mode: this.responseMode,
|
288
|
-
response_type:
|
289
|
-
|
290
|
-
this.clientMetadata.response_types?.find((t) =>
|
291
|
-
metadata['response_types_supported']?.includes(t),
|
292
|
-
) ?? 'code',
|
293
|
-
|
294
|
-
display: options?.display,
|
295
|
-
prompt: options?.prompt,
|
296
|
-
scope: options?.scope || undefined,
|
297
|
-
ui_locales: options?.ui_locales,
|
315
|
+
response_type: 'code' as const,
|
316
|
+
scope: options?.scope ?? this.clientMetadata.scope,
|
298
317
|
}
|
299
318
|
|
300
319
|
if (metadata.pushed_authorization_request_endpoint) {
|
@@ -400,14 +419,14 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
400
419
|
)
|
401
420
|
|
402
421
|
if (issuerParam != null) {
|
403
|
-
if (!server.
|
422
|
+
if (!server.issuer) {
|
404
423
|
throw new OAuthCallbackError(
|
405
424
|
params,
|
406
425
|
'Issuer not found in metadata',
|
407
426
|
stateData.appState,
|
408
427
|
)
|
409
428
|
}
|
410
|
-
if (server.
|
429
|
+
if (server.issuer !== issuerParam) {
|
411
430
|
throw new OAuthCallbackError(
|
412
431
|
params,
|
413
432
|
'Issuer mismatch',
|
@@ -435,7 +454,7 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
435
454
|
|
436
455
|
return { session, state: stateData.appState ?? null }
|
437
456
|
} catch (err) {
|
438
|
-
await server.revoke(tokenSet.access_token)
|
457
|
+
await server.revoke(tokenSet.refresh_token || tokenSet.access_token)
|
439
458
|
|
440
459
|
throw err
|
441
460
|
}
|
@@ -452,11 +471,17 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
452
471
|
*
|
453
472
|
* @param refresh See {@link SessionGetter.getSession}
|
454
473
|
*/
|
455
|
-
async restore(
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
474
|
+
async restore(
|
475
|
+
sub: string,
|
476
|
+
refresh: boolean | 'auto' = 'auto',
|
477
|
+
): Promise<OAuthSession> {
|
478
|
+
// sub arg is lightly typed for convenience of library user
|
479
|
+
assertAtprotoDid(sub)
|
480
|
+
|
481
|
+
const { dpopKey, tokenSet } = await this.sessionGetter.get(sub, {
|
482
|
+
noCache: refresh === true,
|
483
|
+
allowStale: refresh === false,
|
484
|
+
})
|
460
485
|
|
461
486
|
const server = await this.serverFactory.fromIssuer(tokenSet.iss, dpopKey, {
|
462
487
|
noCache: refresh === true,
|
@@ -467,10 +492,12 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
467
492
|
}
|
468
493
|
|
469
494
|
async revoke(sub: string) {
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
495
|
+
// sub arg is lightly typed for convenience of library user
|
496
|
+
assertAtprotoDid(sub)
|
497
|
+
|
498
|
+
const { dpopKey, tokenSet } = await this.sessionGetter.get(sub, {
|
499
|
+
allowStale: true,
|
500
|
+
})
|
474
501
|
|
475
502
|
// NOT using `;(await this.restore(sub, false)).signOut()` because we want
|
476
503
|
// the tokens to be deleted even if it was not possible to fetch the issuer
|
@@ -483,7 +510,10 @@ export class OAuthClient extends CustomEventTarget<OAuthClientEventMap> {
|
|
483
510
|
}
|
484
511
|
}
|
485
512
|
|
486
|
-
protected createSession(
|
513
|
+
protected createSession(
|
514
|
+
server: OAuthServerAgent,
|
515
|
+
sub: AtprotoDid,
|
516
|
+
): OAuthSession {
|
487
517
|
return new OAuthSession(server, sub, this.sessionGetter, this.fetch)
|
488
518
|
}
|
489
519
|
}
|
@@ -10,11 +10,10 @@ import {
|
|
10
10
|
SimpleStore,
|
11
11
|
} from '@atproto-labs/simple-store'
|
12
12
|
import {
|
13
|
-
ALLOW_UNSECURE_ORIGINS,
|
14
13
|
OAuthProtectedResourceMetadata,
|
15
14
|
oauthProtectedResourceMetadataSchema,
|
16
15
|
} from '@atproto/oauth-types'
|
17
|
-
import { contentMime } from './util'
|
16
|
+
import { contentMime } from './util.js'
|
18
17
|
|
19
18
|
export type { GetCachedOptions, OAuthProtectedResourceMetadata }
|
20
19
|
|
@@ -23,6 +22,10 @@ export type ProtectedResourceMetadataCache = SimpleStore<
|
|
23
22
|
OAuthProtectedResourceMetadata
|
24
23
|
>
|
25
24
|
|
25
|
+
export type OAuthProtectedResourceMetadataResolverConfig = {
|
26
|
+
allowHttpResource?: boolean
|
27
|
+
}
|
28
|
+
|
26
29
|
/**
|
27
30
|
* @see {@link https://datatracker.ietf.org/doc/html/draft-ietf-oauth-resource-metadata-05}
|
28
31
|
*/
|
@@ -31,14 +34,17 @@ export class OAuthProtectedResourceMetadataResolver extends CachedGetter<
|
|
31
34
|
OAuthProtectedResourceMetadata
|
32
35
|
> {
|
33
36
|
private readonly fetch: Fetch<unknown>
|
37
|
+
private readonly allowHttpResource: boolean
|
34
38
|
|
35
39
|
constructor(
|
36
40
|
cache: ProtectedResourceMetadataCache,
|
37
41
|
fetch: Fetch = globalThis.fetch,
|
42
|
+
config?: OAuthProtectedResourceMetadataResolverConfig,
|
38
43
|
) {
|
39
44
|
super(async (origin, options) => this.fetchMetadata(origin, options), cache)
|
40
45
|
|
41
46
|
this.fetch = bindFetch(fetch)
|
47
|
+
this.allowHttpResource = config?.allowHttpResource === true
|
42
48
|
}
|
43
49
|
|
44
50
|
async get(
|
@@ -46,27 +52,31 @@ export class OAuthProtectedResourceMetadataResolver extends CachedGetter<
|
|
46
52
|
options?: GetCachedOptions,
|
47
53
|
): Promise<OAuthProtectedResourceMetadata> {
|
48
54
|
const { protocol, origin } = new URL(resource)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
55
|
+
|
56
|
+
if (protocol !== 'https:' && protocol !== 'http:') {
|
57
|
+
throw new TypeError(
|
58
|
+
`Invalid protected resource metadata URL protocol: ${protocol}`,
|
59
|
+
)
|
54
60
|
}
|
55
61
|
|
56
|
-
|
62
|
+
if (protocol === 'http:' && !this.allowHttpResource) {
|
63
|
+
throw new TypeError(
|
64
|
+
`Unsecure resource metadata URL (${protocol}) only allowed in development and test environments`,
|
65
|
+
)
|
66
|
+
}
|
67
|
+
|
68
|
+
return super.get(origin, options)
|
57
69
|
}
|
58
70
|
|
59
71
|
private async fetchMetadata(
|
60
72
|
origin: string,
|
61
73
|
options?: GetCachedOptions,
|
62
74
|
): Promise<OAuthProtectedResourceMetadata> {
|
63
|
-
const headers = new Headers([['accept', 'application/json']])
|
64
|
-
if (options?.noCache) headers.set('cache-control', 'no-cache')
|
65
|
-
|
66
75
|
const url = new URL(`/.well-known/oauth-protected-resource`, origin)
|
67
76
|
const request = new Request(url, {
|
68
77
|
signal: options?.signal,
|
69
|
-
headers,
|
78
|
+
headers: { accept: 'application/json' },
|
79
|
+
cache: options?.noCache ? 'no-cache' : undefined,
|
70
80
|
redirect: 'manual', // response must be 200 OK
|
71
81
|
})
|
72
82
|
|