@mdbase-dev/connect 0.1.0-beta.84 → 0.1.0-beta.86
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/README.md +33 -6
- package/dist/advanced.d.ts +1 -1
- package/dist/application-session.d.ts +31 -10
- package/dist/application-session.js +278 -64
- package/dist/authorization-refresh.d.ts +14 -0
- package/dist/authorization-refresh.js +41 -0
- package/dist/authorization-url.d.ts +1 -0
- package/dist/authorization-url.js +9 -0
- package/dist/browser/integrity.json +1 -1
- package/dist/browser/mdbase-connect.min.js +3 -3
- package/dist/browser/mdbase-connect.min.js.sha384 +1 -1
- package/dist/connect.d.ts +4 -1
- package/dist/connect.js +33 -26
- package/dist/connection-file-transport.d.ts +3 -0
- package/dist/connection-file-transport.js +59 -16
- package/dist/connection-transport-internals.d.ts +2 -0
- package/dist/connection-transport.d.ts +3 -1
- package/dist/connection-transport.js +83 -78
- package/dist/grant-key-leases.d.ts +24 -0
- package/dist/grant-key-leases.js +144 -0
- package/dist/hosted-file-request.d.ts +2 -2
- package/dist/hosted-file-request.js +4 -4
- package/dist/internal-types.d.ts +2 -0
- package/dist/local-file-transport.d.ts +8 -2
- package/dist/local-file-transport.js +71 -20
- package/dist/mdbase-connect.d.ts +1 -0
- package/dist/mdbase-connect.js +3 -0
- package/dist/outcomes.d.ts +12 -12
- package/dist/outcomes.js +6 -0
- package/dist/pending-recovery-transports.d.ts +1 -0
- package/dist/pending-recovery-transports.js +7 -3
- package/dist/retired-grant-keys.d.ts +9 -0
- package/dist/retired-grant-keys.js +56 -0
- package/dist/session.d.ts +36 -7
- package/dist/session.js +287 -34
- package/dist/shared-operation.d.ts +7 -0
- package/dist/shared-operation.js +41 -0
- package/dist/token-response.d.ts +2 -1
- package/dist/token-response.js +2 -1
- package/package.json +2 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GrantKeyStore } from "./crypto.js";
|
|
2
|
+
import type { StoredToken } from "./internal-types.js";
|
|
3
|
+
interface AuthorizationRefreshOptions {
|
|
4
|
+
current: StoredToken | null;
|
|
5
|
+
serverUrl: string;
|
|
6
|
+
keyStore: GrantKeyStore;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
currentToken(): StoredToken | null;
|
|
9
|
+
directCapable(token: StoredToken): boolean;
|
|
10
|
+
removeToken(keyHandle?: string): void;
|
|
11
|
+
storeTokenResponse(body: any, clientId: string, keyHandle?: string): StoredToken;
|
|
12
|
+
}
|
|
13
|
+
export declare function performAuthorizationRefresh(options: AuthorizationRefreshOptions): Promise<StoredToken>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { authorityProofHeaders } from "./authority-proof.js";
|
|
2
|
+
import { apiError, decodeJsonResponse, oauthErrorCode } from "./runtime-utils.js";
|
|
3
|
+
import { connectError } from "./errors.js";
|
|
4
|
+
export async function performAuthorizationRefresh(options) {
|
|
5
|
+
const current = options.current;
|
|
6
|
+
if (!current?.refreshToken) {
|
|
7
|
+
throw connectError("not_authorized", "Reconnect this application to continue.");
|
|
8
|
+
}
|
|
9
|
+
if ((current.refreshExpiresAt ?? 0) <= Date.now()) {
|
|
10
|
+
throw connectError("relay_authorization_expired", "Direct access is still available on this computer, but using the relay requires reconnecting this application.");
|
|
11
|
+
}
|
|
12
|
+
const attemptedRefreshToken = current.refreshToken;
|
|
13
|
+
const refreshUrl = `${options.serverUrl}/oauth/token`;
|
|
14
|
+
const refreshBody = new URLSearchParams({
|
|
15
|
+
grant_type: "refresh_token",
|
|
16
|
+
refresh_token: current.refreshToken,
|
|
17
|
+
client_id: current.clientId
|
|
18
|
+
}).toString();
|
|
19
|
+
const proof = current.authority
|
|
20
|
+
? await authorityProofHeaders(options.keyStore, current, "POST", refreshUrl, refreshBody, current.refreshToken)
|
|
21
|
+
: {};
|
|
22
|
+
const response = await fetch(refreshUrl, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: { "content-type": "application/x-www-form-urlencoded", ...proof },
|
|
25
|
+
body: refreshBody,
|
|
26
|
+
signal: options.signal
|
|
27
|
+
});
|
|
28
|
+
const body = await decodeJsonResponse(response, "invalid_token_response", "The authorization service returned an invalid token response.");
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
const latest = options.currentToken();
|
|
31
|
+
if (latest?.refreshToken && latest.refreshToken !== attemptedRefreshToken)
|
|
32
|
+
return latest;
|
|
33
|
+
if (!options.directCapable(current))
|
|
34
|
+
options.removeToken(current.keyHandle);
|
|
35
|
+
if ((oauthErrorCode(body) ?? body?.error?.code) === "invalid_grant") {
|
|
36
|
+
throw connectError("authorization_expired", body?.error_description ?? body?.error?.message ?? "Reconnect this application to continue.", { status: response.status });
|
|
37
|
+
}
|
|
38
|
+
throw apiError(body, "authorization_expired", "Reconnect this application to continue.", response.status);
|
|
39
|
+
}
|
|
40
|
+
return options.storeTokenResponse(body, current.clientId, current.keyHandle);
|
|
41
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ConnectProblem } from "@mdbase-dev/connect-protocol";
|
|
2
2
|
export declare function cleanAuthorizationParameters(url: URL): URL;
|
|
3
3
|
export declare function isAuthorizationCallbackUrl(value: string): boolean;
|
|
4
|
+
export declare function authorizationCallbackState(value: string): string | null;
|
|
4
5
|
export declare function authorizationReturnToFromProblem(problem: ConnectProblem): string | undefined;
|
|
@@ -15,6 +15,15 @@ export function isAuthorizationCallbackUrl(value) {
|
|
|
15
15
|
return url.searchParams.has("state")
|
|
16
16
|
&& (url.searchParams.has("code") || url.searchParams.has("error"));
|
|
17
17
|
}
|
|
18
|
+
export function authorizationCallbackState(value) {
|
|
19
|
+
try {
|
|
20
|
+
const state = new URL(value).searchParams.get("state");
|
|
21
|
+
return state && state.length > 0 ? state : null;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
18
27
|
export function authorizationReturnToFromProblem(problem) {
|
|
19
28
|
if (!problem.details
|
|
20
29
|
|| typeof problem.details !== "object"
|