@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.
Files changed (81) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +165 -31
  3. package/dist/errors/token-invalid-error.d.ts +7 -0
  4. package/dist/errors/token-invalid-error.d.ts.map +1 -0
  5. package/dist/errors/token-invalid-error.js +16 -0
  6. package/dist/errors/token-invalid-error.js.map +1 -0
  7. package/dist/errors/token-refresh-error.d.ts +7 -0
  8. package/dist/errors/token-refresh-error.d.ts.map +1 -0
  9. package/dist/errors/token-refresh-error.js +16 -0
  10. package/dist/errors/token-refresh-error.js.map +1 -0
  11. package/dist/errors/token-revoked-error.d.ts +7 -0
  12. package/dist/errors/token-revoked-error.d.ts.map +1 -0
  13. package/dist/errors/token-revoked-error.js +16 -0
  14. package/dist/errors/token-revoked-error.js.map +1 -0
  15. package/dist/index.d.ts +9 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +9 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/lock.d.ts +2 -1
  20. package/dist/lock.d.ts.map +1 -1
  21. package/dist/lock.js +2 -2
  22. package/dist/lock.js.map +1 -1
  23. package/dist/oauth-agent.d.ts.map +1 -1
  24. package/dist/oauth-agent.js +14 -9
  25. package/dist/oauth-agent.js.map +1 -1
  26. package/dist/oauth-atp-agent.d.ts +11 -0
  27. package/dist/oauth-atp-agent.d.ts.map +1 -0
  28. package/dist/oauth-atp-agent.js +52 -0
  29. package/dist/oauth-atp-agent.js.map +1 -0
  30. package/dist/oauth-client.d.ts +254 -24
  31. package/dist/oauth-client.d.ts.map +1 -1
  32. package/dist/oauth-client.js +68 -9
  33. package/dist/oauth-client.js.map +1 -1
  34. package/dist/oauth-resolver.d.ts +5 -4
  35. package/dist/oauth-resolver.d.ts.map +1 -1
  36. package/dist/oauth-resolver.js.map +1 -1
  37. package/dist/oauth-server-agent.d.ts.map +1 -1
  38. package/dist/oauth-server-agent.js +85 -29
  39. package/dist/oauth-server-agent.js.map +1 -1
  40. package/dist/runtime-implementation.d.ts +10 -5
  41. package/dist/runtime-implementation.d.ts.map +1 -1
  42. package/dist/runtime.d.ts +3 -3
  43. package/dist/runtime.d.ts.map +1 -1
  44. package/dist/runtime.js +18 -12
  45. package/dist/runtime.js.map +1 -1
  46. package/dist/session-getter.d.ts +19 -0
  47. package/dist/session-getter.d.ts.map +1 -1
  48. package/dist/session-getter.js +134 -42
  49. package/dist/session-getter.js.map +1 -1
  50. package/dist/state-store.d.ts +11 -0
  51. package/dist/state-store.d.ts.map +1 -0
  52. package/dist/state-store.js +3 -0
  53. package/dist/state-store.js.map +1 -0
  54. package/dist/types.d.ts +3 -2
  55. package/dist/types.d.ts.map +1 -1
  56. package/dist/types.js.map +1 -1
  57. package/dist/util.d.ts +10 -3
  58. package/dist/util.d.ts.map +1 -1
  59. package/dist/util.js +43 -23
  60. package/dist/util.js.map +1 -1
  61. package/dist/validate-client-metadata.d.ts.map +1 -1
  62. package/dist/validate-client-metadata.js +17 -0
  63. package/dist/validate-client-metadata.js.map +1 -1
  64. package/package.json +10 -8
  65. package/src/errors/token-invalid-error.ts +9 -0
  66. package/src/{refresh-error.ts → errors/token-refresh-error.ts} +1 -1
  67. package/src/errors/token-revoked-error.ts +9 -0
  68. package/src/index.ts +12 -1
  69. package/src/lock.ts +3 -4
  70. package/src/oauth-agent.ts +20 -9
  71. package/src/oauth-atp-agent.ts +49 -0
  72. package/src/oauth-client.ts +117 -34
  73. package/src/oauth-resolver.ts +4 -4
  74. package/src/oauth-server-agent.ts +9 -9
  75. package/src/runtime-implementation.ts +19 -11
  76. package/src/runtime.ts +13 -17
  77. package/src/session-getter.ts +135 -71
  78. package/src/state-store.ts +12 -0
  79. package/src/types.ts +5 -2
  80. package/src/util.ts +63 -32
  81. package/src/validate-client-metadata.ts +18 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @atproto/oauth-client
2
2
 
3
+ ## 0.1.2-rc.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`2ded0156b`](https://github.com/bluesky-social/atproto/commit/2ded0156b9adf33b9cce66583a375bff922d383b), [`2ded0156b`](https://github.com/bluesky-social/atproto/commit/2ded0156b9adf33b9cce66583a375bff922d383b)]:
8
+ - @atproto/xrpc@0.6.0-rc.0
9
+ - @atproto/api@0.13.0-rc.0
10
+
11
+ ## 0.1.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [#2633](https://github.com/bluesky-social/atproto/pull/2633) [`acc9093d2`](https://github.com/bluesky-social/atproto/commit/acc9093d2845eba02b68fb2f9db33e4f1b59bb10) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add event emitting capability to OAuthClient
16
+
17
+ - Updated dependencies [[`acc9093d2`](https://github.com/bluesky-social/atproto/commit/acc9093d2845eba02b68fb2f9db33e4f1b59bb10), [`acc9093d2`](https://github.com/bluesky-social/atproto/commit/acc9093d2845eba02b68fb2f9db33e4f1b59bb10), [`acc9093d2`](https://github.com/bluesky-social/atproto/commit/acc9093d2845eba02b68fb2f9db33e4f1b59bb10), [`acc9093d2`](https://github.com/bluesky-social/atproto/commit/acc9093d2845eba02b68fb2f9db33e4f1b59bb10)]:
18
+ - @atproto/oauth-types@0.1.1
19
+ - @atproto/jwk@0.1.1
20
+ - @atproto-labs/identity-resolver@0.1.1
21
+ - @atproto-labs/handle-resolver@0.1.1
22
+ - @atproto-labs/did-resolver@0.1.1
23
+ - @atproto-labs/simple-store@0.1.1
24
+ - @atproto-labs/simple-store-memory@0.1.1
25
+
3
26
  ## 0.1.0
4
27
 
5
28
  ### Minor Changes
package/README.md CHANGED
@@ -1,59 +1,86 @@
1
1
  # @atproto/oauth-client: atproto flavoured OAuth client
2
2
 
3
- Core library for implementing ATPROTO OAuth clients.
3
+ Core library for implementing [ATPROTO] OAuth clients.
4
4
 
5
- For a browser specific implementation, see `@atproto/oauth-client-browser`.
6
- For a node specific implementation, see `@atproto/oauth-client-node`.
5
+ For a browser specific implementation, see [@atproto/oauth-client-browser](https://www.npmjs.com/package/@atproto/oauth-client-browser).
6
+ For a node specific implementation, see
7
+ [@atproto/oauth-client-node](https://www.npmjs.com/package/@atproto/oauth-client-node).
8
+
9
+ ## Usage
10
+
11
+ ### Configuration
7
12
 
8
13
  ```ts
9
14
  import { OAuthClient } from '@atproto/oauth-client'
10
15
  import { JoseKey } from '@atproto/jwk-jose' // NodeJS/Browser only
11
16
 
12
17
  const client = new OAuthClient({
13
- handleResolver: 'https://bsky.social', // On node, you should use a DNS based resolver
14
- responseMode: 'query', // or "fragment" or "form_post" (for backend clients only)
18
+ handleResolver: 'https://my-backend.example', // backend instances should use a DNS based resolver
19
+ responseMode: 'query', // or "fragment" (frontend only) or "form_post" (backend only)
20
+
21
+ // These must be the same metadata as the one exposed on the
22
+ // "client_id" endpoint (except when using a loopback client)
15
23
  clientMetadata: {
16
- // These must be the same metadata as the one exposed on the
17
- // "/.well-known/oauth-client-metadata" endpoint (except when using a
18
- // loopback client)
24
+ client_id: 'https://my-app.example/atproto-oauth-client.json',
25
+ jwks_uri: 'https://my-app.example/jwks.json',
19
26
  },
20
27
 
21
28
  runtimeImplementation: {
22
29
  // A runtime specific implementation of the crypto operations needed by the
23
- // OAuth client.
30
+ // OAuth client. See "@atproto/oauth-client-browser" for a browser specific
31
+ // implementation. The following example is suitable for use in NodeJS.
24
32
 
25
33
  createKey(algs: string[]): Promise<Key> {
26
34
  // algs is an ordered array of preferred algorithms (e.g. ['RS256', 'ES256'])
27
35
 
28
36
  // Note, in browser environments, it is better to use non extractable keys
29
- // to prevent leaking the private key. This can be done using the
30
- // WebcryptoKey class from the "@atproto/jwk-webcrypto" package. The
37
+ // to prevent the private key from being stolen. This can be done using
38
+ // the WebcryptoKey class from the "@atproto/jwk-webcrypto" package. The
31
39
  // inconvenient of these keys (which is also what makes them stronger) is
32
40
  // that the only way to persist them across browser reloads is to save
33
41
  // them in the indexed DB.
34
42
  return JoseKey.generate(algs)
35
43
  },
36
- getRandomValues(length: number): Uint8Array | PromiseLike<Uint8Array> {
37
- // length is the number of bytes to generate
38
44
 
39
- const bytes = new Uint8Array(byteLength)
40
- crypto.getRandomValues(bytes)
41
- return bytes
45
+ getRandomValues(length: number): Uint8Array | PromiseLike<Uint8Array> {
46
+ return crypto.getRandomValues(new Uint8Array(length))
42
47
  },
48
+
43
49
  digest(
44
50
  bytes: Uint8Array,
45
- algorithm: { name: 'sha256' | 'sha384' | 'sha512' },
51
+ algorithm: { name: string },
46
52
  ): Uint8Array | PromiseLike<Uint8Array> {
47
53
  // sha256 is required. Unsupported algorithms should throw an error.
48
54
 
49
- const buffer = await this.crypto.subtle.digest(
50
- algorithm.name.startsWith('sha')
51
- ? `SHA-${algorithm.name.slice(-3)}`
52
- : 'invalid',
53
- bytes,
54
- )
55
- return new Uint8Array(buffer)
55
+ if (algorithm.name.startsWith('sha')) {
56
+ const subtleAlgo = `SHA-${algorithm.name.slice(3)}`
57
+ const buffer = await crypto.subtle.digest(subtleAlgo, bytes)
58
+ return new Uint8Array(buffer)
59
+ }
60
+
61
+ throw new TypeError(`Unsupported algorithm: ${algorithm.name}`)
56
62
  },
63
+
64
+ requestLock: <T>(name: string, fn: () => T | PromiseLike<T>): Promise T => {
65
+ // This function is used to prevent concurrent refreshes of the same
66
+ // credentials. It is important to ensure that only one refresh is done at
67
+ // a time to prevent the sessions from being revoked.
68
+
69
+ // The following example shows a simple in-memory lock. In a real
70
+ // application, you should use a more robust solution (e.g. a system wide
71
+ // lock manager). Note that not providing a lock will result in an
72
+ // in-memory lock to be used (DO NOT copy-paste the following code).
73
+
74
+ declare const locks: Map<string, Promise<void>>
75
+
76
+ const current = locks.get(name) || Promise.resolve()
77
+ const next = current.then(fn).catch(() => {}).finally(() => {
78
+ if (locks.get(name) === next) locks.delete(name)
79
+ })
80
+
81
+ locks.set(name, next)
82
+ return next
83
+ }
57
84
  },
58
85
 
59
86
  stateStore: {
@@ -88,7 +115,8 @@ const client = new OAuthClient({
88
115
  keyset: [
89
116
  // For backend clients only, a list of private keys to use for signing
90
117
  // credentials. These keys MUST correspond to the public keys exposed on the
91
- // "jwks_uri" of the client metadata.
118
+ // "jwks_uri" of the client metadata. Note that the jwks JSON corresponding
119
+ // to the following keys can be obtained using the `client.jwks` getter.
92
120
  await JoseKey.fromImportable(process.env.PRIVATE_KEY_1),
93
121
  await JoseKey.fromImportable(process.env.PRIVATE_KEY_2),
94
122
  await JoseKey.fromImportable(process.env.PRIVATE_KEY_3),
@@ -96,6 +124,8 @@ const client = new OAuthClient({
96
124
  })
97
125
  ```
98
126
 
127
+ ### Authentication
128
+
99
129
  ```ts
100
130
  const url = await client.authorize('foo.bsky.team', {
101
131
  state: '434321',
@@ -103,22 +133,126 @@ const url = await client.authorize('foo.bsky.team', {
103
133
  scope: 'email',
104
134
  ui_locales: 'fr',
105
135
  })
136
+ ```
106
137
 
107
- // Make user visit "url". Then, once it was redirected to the callback URI, call:
138
+ Make user visit `url`. Then, once it was redirected to the callback URI, perform the following:
108
139
 
140
+ ```ts
141
+ // Parse the query params from the callback URI
109
142
  const params = new URLSearchParams('code=...&state=...')
143
+
144
+ // Process the callback using the OAuth client
110
145
  const result = await client.callback(params)
111
146
 
112
147
  // Verify the state (e.g. to link to an internal user)
113
- result.state === '434321'
148
+ result.state === '434321' // true
114
149
 
115
- // The authenticated user's identifier
116
- result.agent.sub
150
+ const agent = result.agent
117
151
 
118
152
  // Make an authenticated request to the server. New credentials will be
119
153
  // automatically fetched if needed (causing sessionStore.set() to be called).
120
- await result.agent.request('/xrpc/foo.bar')
154
+ await agent.post({
155
+ text: 'Hello, world!',
156
+ })
121
157
 
122
158
  // revoke credentials on the server (causing sessionStore.del() to be called)
123
- await result.agent.signOut()
159
+ await agent.signOut()
160
+ ```
161
+
162
+ ## Advances use-cases
163
+
164
+ ### Listening for session updates and deletion
165
+
166
+ The `OAuthClient` will emit events whenever a session is updated or deleted.
167
+
168
+ ```ts
169
+ import {
170
+ Session,
171
+ TokenRefreshError,
172
+ TokenRevokedError,
173
+ } from '@atproto/oauth-client'
174
+
175
+ client.addEventListener('updated', (event: CustomEvent<Session>) => {
176
+ console.log('Refreshed tokens were saved in the store:', event.detail)
177
+ })
178
+
179
+ client.addEventListener(
180
+ 'deleted',
181
+ (
182
+ event: CustomEvent<{
183
+ sub: string
184
+ cause: TokenRefreshError | TokenRevokedError | unknown
185
+ }>,
186
+ ) => {
187
+ console.log('Session was deleted from the session store:', event.detail)
188
+
189
+ const { cause } = event.detail
190
+
191
+ if (cause instanceof TokenRefreshError) {
192
+ // - refresh_token unavailable or expired
193
+ // - oauth response error (`cause.cause instanceof OAuthResponseError`)
194
+ // - session data does not match expected values returned by the OAuth server
195
+ } else if (cause instanceof TokenRevokedError) {
196
+ // Session was revoked through:
197
+ // - agent.signOut()
198
+ // - client.revoke(sub)
199
+ } else {
200
+ // An unexpected error occurred, causing the session to be deleted
201
+ }
202
+ },
203
+ )
204
+ ```
205
+
206
+ ### Force user to re-authenticate
207
+
208
+ ```ts
209
+ const url = await client.authorize(handle, {
210
+ prompt: 'login',
211
+ state,
212
+ })
213
+ ```
214
+
215
+ or
216
+
217
+ ```ts
218
+ const url = await client.authorize(handle, {
219
+ state,
220
+ max_age: 600, // Require re-authentication after 10 minutes
221
+ })
222
+ ```
223
+
224
+ ### Silent Sign-In
225
+
226
+ Using silent sign-in requires to handle retries on the callback endpoint.
227
+
228
+ ```ts
229
+ async function createLoginUrl(handle: string, state?: string): string {
230
+ return client.authorize(handle, {
231
+ state,
232
+ // Use "prompt=none" to attempt silent sign-in
233
+ prompt: 'none',
234
+ })
235
+ }
236
+
237
+ async function handleCallback(params: URLSearchParams) {
238
+ try {
239
+ return await client.callback(params)
240
+ } catch (err) {
241
+ // Silent sign-in failed, retry without prompt=none
242
+ if (
243
+ err instanceof OAuthCallbackError &&
244
+ ['login_required', 'consent_required'].includes(err.params.get('error'))
245
+ ) {
246
+ // Do *not* use prompt=none when retrying (to avoid infinite redirects)
247
+ const url = await client.authorize(handle, { state: err.state })
248
+
249
+ // Allow calling code to catch the error and redirect the user to the new URL
250
+ return new MyLoginRequiredError(url)
251
+ }
252
+
253
+ throw err
254
+ }
255
+ }
124
256
  ```
257
+
258
+ [ATPROTO]: https://atproto.com/ 'AT Protocol'
@@ -0,0 +1,7 @@
1
+ export declare class TokenInvalidError extends Error {
2
+ readonly sub: string;
3
+ constructor(sub: string, message?: string, options?: {
4
+ cause?: unknown;
5
+ });
6
+ }
7
+ //# sourceMappingURL=token-invalid-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-invalid-error.d.ts","sourceRoot":"","sources":["../../src/errors/token-invalid-error.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;aAExB,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM,EAC3B,OAAO,SAAwC,EAC/C,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAIhC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenInvalidError = void 0;
4
+ class TokenInvalidError extends Error {
5
+ constructor(sub, message = `The session for "${sub}" is invalid`, options) {
6
+ super(message, options);
7
+ Object.defineProperty(this, "sub", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: sub
12
+ });
13
+ }
14
+ }
15
+ exports.TokenInvalidError = TokenInvalidError;
16
+ //# sourceMappingURL=token-invalid-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-invalid-error.js","sourceRoot":"","sources":["../../src/errors/token-invalid-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YACkB,GAAW,EAC3B,OAAO,GAAG,oBAAoB,GAAG,cAAc,EAC/C,OAA6B;QAE7B,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAJvB;;;;mBAAgB,GAAG;WAAQ;IAK7B,CAAC;CACF;AARD,8CAQC"}
@@ -0,0 +1,7 @@
1
+ export declare class TokenRefreshError extends Error {
2
+ readonly sub: string;
3
+ constructor(sub: string, message: string, options?: {
4
+ cause?: unknown;
5
+ });
6
+ }
7
+ //# sourceMappingURL=token-refresh-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-refresh-error.d.ts","sourceRoot":"","sources":["../../src/errors/token-refresh-error.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;aAExB,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM,EAC3B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAIhC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenRefreshError = void 0;
4
+ class TokenRefreshError extends Error {
5
+ constructor(sub, message, options) {
6
+ super(message, options);
7
+ Object.defineProperty(this, "sub", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: sub
12
+ });
13
+ }
14
+ }
15
+ exports.TokenRefreshError = TokenRefreshError;
16
+ //# sourceMappingURL=token-refresh-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-refresh-error.js","sourceRoot":"","sources":["../../src/errors/token-refresh-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YACkB,GAAW,EAC3B,OAAe,EACf,OAA6B;QAE7B,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAJvB;;;;mBAAgB,GAAG;WAAQ;IAK7B,CAAC;CACF;AARD,8CAQC"}
@@ -0,0 +1,7 @@
1
+ export declare class TokenRevokedError extends Error {
2
+ readonly sub: string;
3
+ constructor(sub: string, message?: string, options?: {
4
+ cause?: unknown;
5
+ });
6
+ }
7
+ //# sourceMappingURL=token-revoked-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-revoked-error.d.ts","sourceRoot":"","sources":["../../src/errors/token-revoked-error.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;aAExB,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM,EAC3B,OAAO,SAAsD,EAC7D,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAIhC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenRevokedError = void 0;
4
+ class TokenRevokedError extends Error {
5
+ constructor(sub, message = `The session for "${sub}" was successfully revoked`, options) {
6
+ super(message, options);
7
+ Object.defineProperty(this, "sub", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: sub
12
+ });
13
+ }
14
+ }
15
+ exports.TokenRevokedError = TokenRevokedError;
16
+ //# sourceMappingURL=token-revoked-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-revoked-error.js","sourceRoot":"","sources":["../../src/errors/token-revoked-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YACkB,GAAW,EAC3B,OAAO,GAAG,oBAAoB,GAAG,4BAA4B,EAC7D,OAA6B;QAE7B,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAJvB;;;;mBAAgB,GAAG;WAAQ;IAK7B,CAAC;CACF;AARD,8CAQC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,10 @@
1
+ export * from '@atproto-labs/did-resolver';
1
2
  export { FetchError, FetchRequestError, FetchResponseError, } from '@atproto-labs/fetch';
3
+ export * from '@atproto-labs/handle-resolver';
4
+ export * from '@atproto/did';
5
+ export * from '@atproto/oauth-types';
2
6
  export * from './oauth-agent.js';
7
+ export * from './oauth-atp-agent.js';
3
8
  export * from './oauth-authorization-server-metadata-resolver.js';
4
9
  export * from './oauth-callback-error.js';
5
10
  export * from './oauth-client.js';
@@ -8,8 +13,11 @@ export * from './oauth-resolver-error.js';
8
13
  export * from './oauth-response-error.js';
9
14
  export * from './oauth-server-agent.js';
10
15
  export * from './oauth-server-factory.js';
11
- export * from './refresh-error.js';
12
16
  export * from './runtime-implementation.js';
13
17
  export * from './session-getter.js';
18
+ export * from './state-store.js';
14
19
  export * from './types.js';
20
+ export * from './errors/token-invalid-error.js';
21
+ export * from './errors/token-refresh-error.js';
22
+ export * from './errors/token-revoked-error.js';
15
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mDAAmD,CAAA;AACjE,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,iDAAiD,CAAA;AAC/D,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,+BAA+B,CAAA;AAE7C,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AAEpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mDAAmD,CAAA;AACjE,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,iDAAiD,CAAA;AAC/D,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAE1B,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iCAAiC,CAAA"}
package/dist/index.js CHANGED
@@ -15,11 +15,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.FetchResponseError = exports.FetchRequestError = exports.FetchError = void 0;
18
+ __exportStar(require("@atproto-labs/did-resolver"), exports);
18
19
  var fetch_1 = require("@atproto-labs/fetch");
19
20
  Object.defineProperty(exports, "FetchError", { enumerable: true, get: function () { return fetch_1.FetchError; } });
20
21
  Object.defineProperty(exports, "FetchRequestError", { enumerable: true, get: function () { return fetch_1.FetchRequestError; } });
21
22
  Object.defineProperty(exports, "FetchResponseError", { enumerable: true, get: function () { return fetch_1.FetchResponseError; } });
23
+ __exportStar(require("@atproto-labs/handle-resolver"), exports);
24
+ __exportStar(require("@atproto/did"), exports);
25
+ __exportStar(require("@atproto/oauth-types"), exports);
22
26
  __exportStar(require("./oauth-agent.js"), exports);
27
+ __exportStar(require("./oauth-atp-agent.js"), exports);
23
28
  __exportStar(require("./oauth-authorization-server-metadata-resolver.js"), exports);
24
29
  __exportStar(require("./oauth-callback-error.js"), exports);
25
30
  __exportStar(require("./oauth-client.js"), exports);
@@ -28,8 +33,11 @@ __exportStar(require("./oauth-resolver-error.js"), exports);
28
33
  __exportStar(require("./oauth-response-error.js"), exports);
29
34
  __exportStar(require("./oauth-server-agent.js"), exports);
30
35
  __exportStar(require("./oauth-server-factory.js"), exports);
31
- __exportStar(require("./refresh-error.js"), exports);
32
36
  __exportStar(require("./runtime-implementation.js"), exports);
33
37
  __exportStar(require("./session-getter.js"), exports);
38
+ __exportStar(require("./state-store.js"), exports);
34
39
  __exportStar(require("./types.js"), exports);
40
+ __exportStar(require("./errors/token-invalid-error.js"), exports);
41
+ __exportStar(require("./errors/token-refresh-error.js"), exports);
42
+ __exportStar(require("./errors/token-revoked-error.js"), exports);
35
43
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAI4B;AAH1B,mGAAA,UAAU,OAAA;AACV,0GAAA,iBAAiB,OAAA;AACjB,2GAAA,kBAAkB,OAAA;AAEpB,mDAAgC;AAChC,oFAAiE;AACjE,4DAAyC;AACzC,oDAAiC;AACjC,kFAA+D;AAC/D,4DAAyC;AACzC,4DAAyC;AACzC,0DAAuC;AACvC,4DAAyC;AACzC,qDAAkC;AAClC,8DAA2C;AAC3C,sDAAmC;AACnC,6CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6DAA0C;AAC1C,6CAI4B;AAH1B,mGAAA,UAAU,OAAA;AACV,0GAAA,iBAAiB,OAAA;AACjB,2GAAA,kBAAkB,OAAA;AAEpB,gEAA6C;AAE7C,+CAA4B;AAC5B,uDAAoC;AAEpC,mDAAgC;AAChC,uDAAoC;AACpC,oFAAiE;AACjE,4DAAyC;AACzC,oDAAiC;AACjC,kFAA+D;AAC/D,4DAAyC;AACzC,4DAAyC;AACzC,0DAAuC;AACvC,4DAAyC;AACzC,8DAA2C;AAC3C,sDAAmC;AACnC,mDAAgC;AAChC,6CAA0B;AAE1B,kEAA+C;AAC/C,kEAA+C;AAC/C,kEAA+C"}
package/dist/lock.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export declare function requestLocalLock<T>(name: string, fn: () => T | PromiseLike<T>): Promise<T>;
1
+ import { RuntimeLock } from './runtime-implementation.js';
2
+ export declare const requestLocalLock: RuntimeLock;
2
3
  //# sourceMappingURL=lock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lock.d.ts","sourceRoot":"","sources":["../src/lock.ts"],"names":[],"mappings":"AAsBA,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,CAAC,CAQZ"}
1
+ {"version":3,"file":"lock.d.ts","sourceRoot":"","sources":["../src/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAwBzD,eAAO,MAAM,gBAAgB,EAAE,WAQ9B,CAAA"}
package/dist/lock.js CHANGED
@@ -19,7 +19,7 @@ function acquireLocalLock(name) {
19
19
  locks.set(name, next);
20
20
  });
21
21
  }
22
- function requestLocalLock(name, fn) {
22
+ const requestLocalLock = (name, fn) => {
23
23
  return acquireLocalLock(name).then(async (release) => {
24
24
  try {
25
25
  return await fn();
@@ -28,6 +28,6 @@ function requestLocalLock(name, fn) {
28
28
  release();
29
29
  }
30
30
  });
31
- }
31
+ };
32
32
  exports.requestLocalLock = requestLocalLock;
33
33
  //# sourceMappingURL=lock.js.map
package/dist/lock.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lock.js","sourceRoot":"","sources":["../src/lock.ts"],"names":[],"mappings":";;;AAAA,MAAM,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAA;AAE/C,SAAS,gBAAgB,CAAC,IAAa;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;QACpC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAA;QACjD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YAC1B,OAAO,IAAI,O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B;IAajC,IAAI,cAAc,IAAI,QAAQ,CAAC,gCAAgC,CAAC,CAE/D;IAEY,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7C;;OAEG;cACa,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAK3D,OAAO,IAAI,OAAO,CAAC;QACvB,QAAQ,CAAC,EAAE,UAAU,CAAA;QACrB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACZ,CAAC;IAkBI,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAYxB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;CA2DvE"}
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OAuthAgent = void 0;
4
4
  const fetch_1 = require("@atproto-labs/fetch");
5
5
  const jwk_1 = require("@atproto/jwk");
6
+ const token_invalid_error_js_1 = require("./errors/token-invalid-error.js");
7
+ const token_revoked_error_js_1 = require("./errors/token-revoked-error.js");
6
8
  const fetch_dpop_js_1 = require("./fetch-dpop.js");
7
9
  const ReadableStream = globalThis.ReadableStream;
8
10
  class OAuthAgent {
@@ -75,7 +77,7 @@ class OAuthAgent {
75
77
  await this.server.revoke(tokenSet.access_token);
76
78
  }
77
79
  finally {
78
- await this.sessionGetter.delStored(this.sub);
80
+ await this.sessionGetter.delStored(this.sub, new token_revoked_error_js_1.TokenRevokedError(this.sub));
79
81
  }
80
82
  }
81
83
  async request(pathname, init) {
@@ -90,12 +92,12 @@ class OAuthAgent {
90
92
  headers,
91
93
  });
92
94
  // If the token is not expired, we don't need to refresh it
93
- if (!isTokenExpiredResponse(initialResponse)) {
95
+ if (!isInvalidTokenResponse(initialResponse)) {
94
96
  return initialResponse;
95
97
  }
96
98
  let tokenSetFresh;
97
99
  try {
98
- // "true" here will cause the token to be refreshed
100
+ // Force a refresh
99
101
  tokenSetFresh = await this.getTokenSet(true);
100
102
  }
101
103
  catch (err) {
@@ -112,12 +114,15 @@ class OAuthAgent {
112
114
  const finalUrl = new URL(pathname, tokenSetFresh.aud);
113
115
  headers.set('Authorization', finalAuth);
114
116
  const finalResponse = await this.dpopFetch(finalUrl, { ...init, headers });
115
- // There is no need to keep the session in the store if the token is expired
116
- // and there is no way to refresh it.
117
- if (isTokenExpiredResponse(finalResponse)) {
117
+ // The token was successfully refreshed, but is still not accepted by the
118
+ // resource server. This might be due to the resource server not accepting
119
+ // credentials from the authorization server (e.g. because some migration
120
+ // occurred). Any ways, there is no point in keeping the session.
121
+ if (isInvalidTokenResponse(finalResponse)) {
118
122
  // TODO: Is there a "softer" way to handle this, e.g. by marking the
119
- // session as "expired" and allow the user to trigger a new login?
120
- await this.sessionGetter.delStored(this.sub);
123
+ // session as "expired" in the session store, allowing the user to trigger
124
+ // a new login (using login_hint/id_token_hint)?
125
+ await this.sessionGetter.delStored(this.sub, new token_invalid_error_js_1.TokenInvalidError(this.sub));
121
126
  }
122
127
  return finalResponse;
123
128
  }
@@ -127,7 +132,7 @@ exports.OAuthAgent = OAuthAgent;
127
132
  * @see {@link https://datatracker.ietf.org/doc/html/rfc6750#section-3}
128
133
  * @see {@link https://datatracker.ietf.org/doc/html/rfc9449#name-resource-server-provided-no}
129
134
  */
130
- function isTokenExpiredResponse(response) {
135
+ function isInvalidTokenResponse(response) {
131
136
  if (response.status !== 401)
132
137
  return false;
133
138
  const wwwAuth = response.headers.get('WWW-Authenticate');
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-agent.js","sourceRoot":"","sources":["../src/oauth-agent.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,sCAA0D;AAG1D,mDAAkD;AAIlD,MAAM,cAAc,GAAG,UAAU,CAAC,cAErB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G,IAAI,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,CAAA;QAErD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,SAAS,CAAC,CAAA;QAEvC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;QAE1E,yEAAyE;QACzE,0EAA0E;QAC1E,yEAAyE;QACzE,iEAAiE;QACjE,IAAI,sBAAsB,CAAC,aAAa,CAAC,EAAE,CAAC;YAC1C,oEAAoE;YACpE,0EAA0E;YAC1E,gDAAgD;YAChD,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAChC,IAAI,CAAC,GAAG,EACR,IAAI,0CAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAChC,CAAA;QACH,CAAC;QAED,OAAO,aAAa,CAAA;IACtB,CAAC;CACF;AApID,gCAoIC;AAED;;;GAGG;AACH,SAAS,sBAAsB,CAAC,QAAkB;IAChD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,KAAK,CAAA;IACzC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IACxD,OAAO,CACL,OAAO,IAAI,IAAI;QACf,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC9D,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAC1C,CAAA;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Agent } from '@atproto/api';
2
+ import { OAuthAgent } from './oauth-agent.js';
3
+ export declare class OAuthAtpAgent extends Agent {
4
+ readonly oauthAgent: OAuthAgent;
5
+ constructor(oauthAgent: OAuthAgent);
6
+ clone(): this;
7
+ get did(): string;
8
+ signOut(): Promise<void>;
9
+ refreshIfNeeded(): Promise<void>;
10
+ }
11
+ //# sourceMappingURL=oauth-atp-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-atp-agent.d.ts","sourceRoot":"","sources":["../src/oauth-atp-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAIpC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,qBAAa,aAAc,SAAQ,KAAK;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU;gBAAtB,UAAU,EAAE,UAAU;IAyB3C,KAAK,IAAI,IAAI;IAKb,IAAI,GAAG,IAAI,MAAM,CAEhB;IAEK,OAAO;IAIA,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9C"}