@atcute/oauth-browser-client 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/server-agent.d.ts +1 -1
- package/dist/agents/sessions.d.ts +4 -4
- package/dist/agents/user-agent.d.ts +1 -1
- package/dist/dpop.js +3 -2
- package/dist/dpop.js.map +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/resolvers.d.ts +2 -2
- package/dist/store/db.d.ts +1 -1
- package/dist/types/identity.d.ts +1 -1
- package/dist/types/token.d.ts +1 -1
- package/dist/utils/runtime.d.ts +1 -3
- package/dist/utils/runtime.js +5 -25
- package/dist/utils/runtime.js.map +1 -1
- package/dist/utils/strings.d.ts +1 -1
- package/lib/agents/server-agent.ts +2 -2
- package/lib/agents/sessions.ts +6 -6
- package/lib/agents/user-agent.ts +1 -1
- package/lib/dpop.ts +4 -2
- package/lib/errors.ts +1 -1
- package/lib/resolvers.ts +3 -3
- package/lib/store/db.ts +1 -1
- package/lib/types/identity.ts +1 -1
- package/lib/types/token.ts +1 -1
- package/lib/utils/runtime.ts +6 -30
- package/lib/utils/strings.ts +1 -1
- package/package.json +4 -2
|
@@ -5,7 +5,7 @@ export interface SessionGetOptions {
|
|
|
5
5
|
noCache?: boolean;
|
|
6
6
|
allowStale?: boolean;
|
|
7
7
|
}
|
|
8
|
-
export declare const getSession: (sub: At.
|
|
9
|
-
export declare const storeSession: (sub: At.
|
|
10
|
-
export declare const deleteStoredSession: (sub: At.
|
|
11
|
-
export declare const listStoredSessions: () => At.
|
|
8
|
+
export declare const getSession: (sub: At.Did, options?: SessionGetOptions) => Promise<Session>;
|
|
9
|
+
export declare const storeSession: (sub: At.Did, newSession: Session) => Promise<void>;
|
|
10
|
+
export declare const deleteStoredSession: (sub: At.Did) => void;
|
|
11
|
+
export declare const listStoredSessions: () => At.Did[];
|
|
@@ -6,7 +6,7 @@ export declare class OAuthUserAgent implements FetchHandlerObject {
|
|
|
6
6
|
#private;
|
|
7
7
|
session: Session;
|
|
8
8
|
constructor(session: Session);
|
|
9
|
-
get sub(): At.
|
|
9
|
+
get sub(): At.Did;
|
|
10
10
|
getSession(options?: SessionGetOptions): Promise<Session>;
|
|
11
11
|
signOut(): Promise<void>;
|
|
12
12
|
handle(pathname: string, init?: RequestInit): Promise<Response>;
|
package/dist/dpop.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { fromBase64Url, toBase64Url } from '@atcute/multibase';
|
|
1
2
|
import { database } from './environment.js';
|
|
2
3
|
import { extractContentType } from './utils/response.js';
|
|
3
|
-
import { encoder,
|
|
4
|
+
import { encoder, generateJti, stringToSha256 } from './utils/runtime.js';
|
|
4
5
|
const ES256_ALG = { name: 'ECDSA', namedCurve: 'P-256' };
|
|
5
6
|
export const createES256Key = async () => {
|
|
6
7
|
const pair = await crypto.subtle.generateKey(ES256_ALG, true, ['sign', 'verify']);
|
|
@@ -42,7 +43,7 @@ export const createDPoPFetch = (issuer, dpopKey, isAuthServer) => {
|
|
|
42
43
|
const request = init == null && input instanceof Request ? input : new Request(input, init);
|
|
43
44
|
const authorizationHeader = request.headers.get('authorization');
|
|
44
45
|
const ath = authorizationHeader?.startsWith('DPoP ')
|
|
45
|
-
? await
|
|
46
|
+
? await stringToSha256(authorizationHeader.slice(5))
|
|
46
47
|
: undefined;
|
|
47
48
|
const { method, url } = request;
|
|
48
49
|
const { origin } = new URL(url);
|
package/dist/dpop.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dpop.js","sourceRoot":"","sources":["../lib/dpop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"dpop.js","sourceRoot":"","sources":["../lib/dpop.ts"],"names":[],"mappings":"AAA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OAAO,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;YACnD,CAAC;QACF,CAAC;IACF,CAAC;IAED,iFAAiF;IACjF,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QACzD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,kBAAkB,EAAE,CAAC;YAC5F,IAAI,CAAC;gBACJ,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;gBAC3C,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,gBAAgB,CAAC;YACzE,CAAC;YAAC,MAAM,CAAC;gBACR,kEAAkE;gBAClE,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ export declare class ResolverError extends Error {
|
|
|
9
9
|
name: string;
|
|
10
10
|
}
|
|
11
11
|
export declare class TokenRefreshError extends Error {
|
|
12
|
-
readonly sub: At.
|
|
12
|
+
readonly sub: At.Did;
|
|
13
13
|
name: string;
|
|
14
|
-
constructor(sub: At.
|
|
14
|
+
constructor(sub: At.Did, message: string, options?: ErrorOptions);
|
|
15
15
|
}
|
|
16
16
|
export declare class OAuthResponseError extends Error {
|
|
17
17
|
readonly response: Response;
|
package/dist/resolvers.d.ts
CHANGED
|
@@ -8,13 +8,13 @@ import type { AuthorizationServerMetadata, ProtectedResourceMetadata } from './t
|
|
|
8
8
|
* @param handle Domain handle to resolve
|
|
9
9
|
* @returns DID identifier resolved from the domain handle
|
|
10
10
|
*/
|
|
11
|
-
export declare const resolveHandle: (handle: string) => Promise<At.
|
|
11
|
+
export declare const resolveHandle: (handle: string) => Promise<At.Did>;
|
|
12
12
|
/**
|
|
13
13
|
* Get DID documents of did:plc (via plc.directory) and did:web identifiers
|
|
14
14
|
* @param did DID identifier we're seeking DID doc from
|
|
15
15
|
* @returns Retrieved DID document
|
|
16
16
|
*/
|
|
17
|
-
export declare const getDidDocument: (did: At.
|
|
17
|
+
export declare const getDidDocument: (did: At.Did) => Promise<DidDocument>;
|
|
18
18
|
/**
|
|
19
19
|
* Get OAuth protected resource metadata from a host
|
|
20
20
|
* @param host URL of the host
|
package/dist/store/db.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface OAuthDatabaseOptions {
|
|
|
8
8
|
export type OAuthDatabase = ReturnType<typeof createOAuthDatabase>;
|
|
9
9
|
export declare const createOAuthDatabase: ({ name }: OAuthDatabaseOptions) => {
|
|
10
10
|
dispose: () => void;
|
|
11
|
-
sessions: SimpleStore<`did:${string}`, Session>;
|
|
11
|
+
sessions: SimpleStore<`did:${string}:${string}`, Session>;
|
|
12
12
|
states: SimpleStore<string, {
|
|
13
13
|
dpopKey: DPoPKey;
|
|
14
14
|
metadata: AuthorizationServerMetadata;
|
package/dist/types/identity.d.ts
CHANGED
package/dist/types/token.d.ts
CHANGED
package/dist/utils/runtime.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export declare const encoder: TextEncoder;
|
|
2
2
|
export declare const locks: LockManager | undefined;
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const fromBase64Url: (input: string) => Uint8Array;
|
|
5
|
-
export declare const toSha256: (input: string) => Promise<string>;
|
|
3
|
+
export declare const stringToSha256: (input: string) => Promise<string>;
|
|
6
4
|
export declare const randomBytes: (length: number) => string;
|
|
7
5
|
export declare const generateState: () => string;
|
|
8
6
|
export declare const generatePKCE: () => Promise<{
|
package/dist/utils/runtime.js
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
|
+
import { toBase64Url } from '@atcute/multibase';
|
|
2
|
+
import { toSha256 } from '@atcute/uint8array';
|
|
1
3
|
export const encoder = new TextEncoder();
|
|
2
4
|
export const locks = typeof navigator !== 'undefined' ? navigator.locks : undefined;
|
|
3
|
-
export const
|
|
4
|
-
const CHUNK_SIZE = 0x8000;
|
|
5
|
-
const arr = [];
|
|
6
|
-
for (let i = 0; i < input.byteLength; i += CHUNK_SIZE) {
|
|
7
|
-
// @ts-expect-error
|
|
8
|
-
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
9
|
-
}
|
|
10
|
-
return btoa(arr.join('')).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
11
|
-
};
|
|
12
|
-
export const fromBase64Url = (input) => {
|
|
13
|
-
try {
|
|
14
|
-
const binary = atob(input.replace(/-/g, '+').replace(/_/g, '/').replace(/\s/g, ''));
|
|
15
|
-
const bytes = new Uint8Array(binary.length);
|
|
16
|
-
for (let i = 0; i < binary.length; i++) {
|
|
17
|
-
bytes[i] = binary.charCodeAt(i);
|
|
18
|
-
}
|
|
19
|
-
return bytes;
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
throw new TypeError(`invalid base64url`, { cause: err });
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
export const toSha256 = async (input) => {
|
|
5
|
+
export const stringToSha256 = async (input) => {
|
|
26
6
|
const bytes = encoder.encode(input);
|
|
27
|
-
const digest = await
|
|
7
|
+
const digest = await toSha256(bytes);
|
|
28
8
|
return toBase64Url(new Uint8Array(digest));
|
|
29
9
|
};
|
|
30
10
|
export const randomBytes = (length) => {
|
|
@@ -37,7 +17,7 @@ export const generatePKCE = async () => {
|
|
|
37
17
|
const verifier = randomBytes(32);
|
|
38
18
|
return {
|
|
39
19
|
verifier: verifier,
|
|
40
|
-
challenge: await
|
|
20
|
+
challenge: await stringToSha256(verifier),
|
|
41
21
|
method: 'S256',
|
|
42
22
|
};
|
|
43
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../lib/utils/runtime.ts"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CAAC,CAAC;AACtB,IAAI,YAAgC,CAAC;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,GAAW,EAAE;IACvC,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7D,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,aAAa,CAAC,CAAC;IAC9D,aAAa,GAAG,SAAS,GAAG,CAAC,CAAC;IAE9B,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,YAAY,EAAE,CAAC;AACpD,CAAC,CAAC"}
|
package/dist/utils/strings.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export class OAuthServerAgent {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
async refresh({ sub, token }: { sub: At.
|
|
77
|
+
async refresh({ sub, token }: { sub: At.Did; token: TokenInfo }): Promise<TokenInfo> {
|
|
78
78
|
if (!token.refresh) {
|
|
79
79
|
throw new TokenRefreshError(sub, 'no refresh token available');
|
|
80
80
|
}
|
|
@@ -133,7 +133,7 @@ export class OAuthServerAgent {
|
|
|
133
133
|
return {
|
|
134
134
|
token: token,
|
|
135
135
|
info: {
|
|
136
|
-
sub: sub as At.
|
|
136
|
+
sub: sub as At.Did,
|
|
137
137
|
aud: resolved.identity.pds.href,
|
|
138
138
|
server: pick(resolved.metadata, [
|
|
139
139
|
'issuer',
|
package/lib/agents/sessions.ts
CHANGED
|
@@ -14,9 +14,9 @@ export interface SessionGetOptions {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
type PendingItem<V> = Promise<{ value: V; isFresh: boolean }>;
|
|
17
|
-
const pending = new Map<At.
|
|
17
|
+
const pending = new Map<At.Did, PendingItem<Session>>();
|
|
18
18
|
|
|
19
|
-
export const getSession = async (sub: At.
|
|
19
|
+
export const getSession = async (sub: At.Did, options?: SessionGetOptions): Promise<Session> => {
|
|
20
20
|
options?.signal?.throwIfAborted();
|
|
21
21
|
|
|
22
22
|
let allowStored = isTokenUsable;
|
|
@@ -89,7 +89,7 @@ export const getSession = async (sub: At.DID, options?: SessionGetOptions): Prom
|
|
|
89
89
|
return value;
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
-
export const storeSession = async (sub: At.
|
|
92
|
+
export const storeSession = async (sub: At.Did, newSession: Session): Promise<void> => {
|
|
93
93
|
try {
|
|
94
94
|
database.sessions.set(sub, newSession);
|
|
95
95
|
} catch (err) {
|
|
@@ -98,18 +98,18 @@ export const storeSession = async (sub: At.DID, newSession: Session): Promise<vo
|
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
export const deleteStoredSession = (sub: At.
|
|
101
|
+
export const deleteStoredSession = (sub: At.Did): void => {
|
|
102
102
|
database.sessions.delete(sub);
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
export const listStoredSessions = (): At.
|
|
105
|
+
export const listStoredSessions = (): At.Did[] => {
|
|
106
106
|
return database.sessions.keys();
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
const returnTrue = () => true;
|
|
110
110
|
const returnFalse = () => false;
|
|
111
111
|
|
|
112
|
-
const refreshToken = async (sub: At.
|
|
112
|
+
const refreshToken = async (sub: At.Did, storedSession: Session | undefined): Promise<Session> => {
|
|
113
113
|
if (storedSession === undefined) {
|
|
114
114
|
throw new TokenRefreshError(sub, `session deleted by another tab`);
|
|
115
115
|
}
|
package/lib/agents/user-agent.ts
CHANGED
package/lib/dpop.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { fromBase64Url, toBase64Url } from '@atcute/multibase';
|
|
2
|
+
|
|
1
3
|
import { database } from './environment.js';
|
|
2
4
|
import type { DPoPKey } from './types/dpop.js';
|
|
3
5
|
import { extractContentType } from './utils/response.js';
|
|
4
|
-
import { encoder,
|
|
6
|
+
import { encoder, generateJti, stringToSha256 } from './utils/runtime.js';
|
|
5
7
|
|
|
6
8
|
const ES256_ALG = { name: 'ECDSA', namedCurve: 'P-256' } as const;
|
|
7
9
|
|
|
@@ -67,7 +69,7 @@ export const createDPoPFetch = (issuer: string, dpopKey: DPoPKey, isAuthServer?:
|
|
|
67
69
|
|
|
68
70
|
const authorizationHeader = request.headers.get('authorization');
|
|
69
71
|
const ath = authorizationHeader?.startsWith('DPoP ')
|
|
70
|
-
? await
|
|
72
|
+
? await stringToSha256(authorizationHeader.slice(5))
|
|
71
73
|
: undefined;
|
|
72
74
|
|
|
73
75
|
const { method, url } = request;
|
package/lib/errors.ts
CHANGED
package/lib/resolvers.ts
CHANGED
|
@@ -16,7 +16,7 @@ const DID_WEB_RE = /^([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*(?:\.[a-zA-Z]{2,}))$/;
|
|
|
16
16
|
* @param handle Domain handle to resolve
|
|
17
17
|
* @returns DID identifier resolved from the domain handle
|
|
18
18
|
*/
|
|
19
|
-
export const resolveHandle = async (handle: string): Promise<At.
|
|
19
|
+
export const resolveHandle = async (handle: string): Promise<At.Did> => {
|
|
20
20
|
const url = DEFAULT_APPVIEW_URL + `/xrpc/com.atproto.identity.resolveHandle` + `?handle=${handle}`;
|
|
21
21
|
|
|
22
22
|
const response = await fetch(url);
|
|
@@ -35,7 +35,7 @@ export const resolveHandle = async (handle: string): Promise<At.DID> => {
|
|
|
35
35
|
* @param did DID identifier we're seeking DID doc from
|
|
36
36
|
* @returns Retrieved DID document
|
|
37
37
|
*/
|
|
38
|
-
export const getDidDocument = async (did: At.
|
|
38
|
+
export const getDidDocument = async (did: At.Did): Promise<DidDocument> => {
|
|
39
39
|
const colon_index = did.indexOf(':', 4);
|
|
40
40
|
|
|
41
41
|
const type = did.slice(4, colon_index);
|
|
@@ -151,7 +151,7 @@ export const getAuthorizationServerMetadata = async (host: string): Promise<Auth
|
|
|
151
151
|
export const resolveFromIdentity = async (
|
|
152
152
|
ident: string,
|
|
153
153
|
): Promise<{ identity: IdentityMetadata; metadata: AuthorizationServerMetadata }> => {
|
|
154
|
-
let did: At.
|
|
154
|
+
let did: At.Did;
|
|
155
155
|
if (isDid(ident)) {
|
|
156
156
|
did = ident;
|
|
157
157
|
} else {
|
package/lib/store/db.ts
CHANGED
package/lib/types/identity.ts
CHANGED
package/lib/types/token.ts
CHANGED
package/lib/utils/runtime.ts
CHANGED
|
@@ -1,37 +1,13 @@
|
|
|
1
|
+
import { toBase64Url } from '@atcute/multibase';
|
|
2
|
+
import { toSha256 } from '@atcute/uint8array';
|
|
3
|
+
|
|
1
4
|
export const encoder = new TextEncoder();
|
|
2
5
|
|
|
3
6
|
export const locks: LockManager | undefined = typeof navigator !== 'undefined' ? navigator.locks : undefined;
|
|
4
7
|
|
|
5
|
-
export const
|
|
6
|
-
const CHUNK_SIZE = 0x8000;
|
|
7
|
-
const arr = [];
|
|
8
|
-
|
|
9
|
-
for (let i = 0; i < input.byteLength; i += CHUNK_SIZE) {
|
|
10
|
-
// @ts-expect-error
|
|
11
|
-
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return btoa(arr.join('')).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const fromBase64Url = (input: string): Uint8Array => {
|
|
18
|
-
try {
|
|
19
|
-
const binary = atob(input.replace(/-/g, '+').replace(/_/g, '/').replace(/\s/g, ''));
|
|
20
|
-
const bytes = new Uint8Array(binary.length);
|
|
21
|
-
|
|
22
|
-
for (let i = 0; i < binary.length; i++) {
|
|
23
|
-
bytes[i] = binary.charCodeAt(i);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return bytes;
|
|
27
|
-
} catch (err) {
|
|
28
|
-
throw new TypeError(`invalid base64url`, { cause: err });
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const toSha256 = async (input: string): Promise<string> => {
|
|
8
|
+
export const stringToSha256 = async (input: string): Promise<string> => {
|
|
33
9
|
const bytes = encoder.encode(input);
|
|
34
|
-
const digest = await
|
|
10
|
+
const digest = await toSha256(bytes);
|
|
35
11
|
|
|
36
12
|
return toBase64Url(new Uint8Array(digest));
|
|
37
13
|
};
|
|
@@ -49,7 +25,7 @@ export const generatePKCE = async (): Promise<{ verifier: string; challenge: str
|
|
|
49
25
|
|
|
50
26
|
return {
|
|
51
27
|
verifier: verifier,
|
|
52
|
-
challenge: await
|
|
28
|
+
challenge: await stringToSha256(verifier),
|
|
53
29
|
method: 'S256',
|
|
54
30
|
};
|
|
55
31
|
};
|
package/lib/utils/strings.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@atcute/oauth-browser-client",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.17",
|
|
5
5
|
"description": "minimal OAuth browser client implementation for AT Protocol",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
},
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@atcute/client": "^
|
|
22
|
+
"@atcute/client": "^3.0.0",
|
|
23
|
+
"@atcute/multibase": "^1.1.3",
|
|
24
|
+
"@atcute/uint8array": "^1.0.1"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
25
27
|
"@types/bun": "^1.2.1"
|