@gakr-gakr/google-meet 0.1.0
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/autobot.plugin.json +532 -0
- package/doctor-contract-api.ts +1 -0
- package/index.ts +1224 -0
- package/package.json +47 -0
- package/src/agent-consult.ts +158 -0
- package/src/calendar.ts +252 -0
- package/src/cli.ts +2350 -0
- package/src/config-compat.ts +84 -0
- package/src/config.ts +589 -0
- package/src/create.ts +157 -0
- package/src/drive.ts +72 -0
- package/src/google-api-errors.ts +20 -0
- package/src/meet.ts +1024 -0
- package/src/node-host.ts +520 -0
- package/src/oauth.ts +229 -0
- package/src/realtime-node.ts +780 -0
- package/src/realtime.ts +1334 -0
- package/src/runtime.ts +1008 -0
- package/src/setup.ts +285 -0
- package/src/transports/chrome-browser-proxy.ts +204 -0
- package/src/transports/chrome-create.ts +364 -0
- package/src/transports/chrome.ts +1065 -0
- package/src/transports/twilio.ts +57 -0
- package/src/transports/types.ts +147 -0
- package/src/voice-call-gateway.ts +241 -0
- package/tsconfig.json +16 -0
package/src/oauth.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { generateHexPkceVerifierChallenge } from "autobot/plugin-sdk/provider-auth";
|
|
2
|
+
import {
|
|
3
|
+
generateOAuthState,
|
|
4
|
+
parseOAuthCallbackInput,
|
|
5
|
+
waitForLocalOAuthCallback,
|
|
6
|
+
} from "autobot/plugin-sdk/provider-auth-runtime";
|
|
7
|
+
import { fetchWithSsrFGuard } from "autobot/plugin-sdk/ssrf-runtime";
|
|
8
|
+
|
|
9
|
+
const GOOGLE_MEET_REDIRECT_URI = "http://localhost:8085/oauth2callback";
|
|
10
|
+
const GOOGLE_MEET_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
11
|
+
const GOOGLE_MEET_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
12
|
+
const GOOGLE_MEET_TOKEN_HOST = "oauth2.googleapis.com";
|
|
13
|
+
const GOOGLE_MEET_SCOPES = [
|
|
14
|
+
"https://www.googleapis.com/auth/meetings.space.created",
|
|
15
|
+
"https://www.googleapis.com/auth/meetings.space.readonly",
|
|
16
|
+
"https://www.googleapis.com/auth/meetings.space.settings",
|
|
17
|
+
"https://www.googleapis.com/auth/meetings.conference.media.readonly",
|
|
18
|
+
"https://www.googleapis.com/auth/calendar.events.readonly",
|
|
19
|
+
"https://www.googleapis.com/auth/drive.meet.readonly",
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
export type GoogleMeetOAuthTokens = {
|
|
23
|
+
accessToken: string;
|
|
24
|
+
expiresAt: number;
|
|
25
|
+
refreshToken?: string;
|
|
26
|
+
scope?: string;
|
|
27
|
+
tokenType?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function buildGoogleMeetAuthUrl(params: {
|
|
31
|
+
clientId: string;
|
|
32
|
+
challenge: string;
|
|
33
|
+
state: string;
|
|
34
|
+
redirectUri?: string;
|
|
35
|
+
scopes?: readonly string[];
|
|
36
|
+
}): string {
|
|
37
|
+
const search = new URLSearchParams({
|
|
38
|
+
client_id: params.clientId,
|
|
39
|
+
response_type: "code",
|
|
40
|
+
redirect_uri: params.redirectUri ?? GOOGLE_MEET_REDIRECT_URI,
|
|
41
|
+
scope: (params.scopes ?? GOOGLE_MEET_SCOPES).join(" "),
|
|
42
|
+
code_challenge: params.challenge,
|
|
43
|
+
code_challenge_method: "S256",
|
|
44
|
+
access_type: "offline",
|
|
45
|
+
prompt: "consent",
|
|
46
|
+
state: params.state,
|
|
47
|
+
});
|
|
48
|
+
return `${GOOGLE_MEET_AUTH_URL}?${search.toString()}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function executeGoogleTokenRequest(body: URLSearchParams): Promise<GoogleMeetOAuthTokens> {
|
|
52
|
+
const { response, release } = await fetchWithSsrFGuard({
|
|
53
|
+
url: GOOGLE_MEET_TOKEN_URL,
|
|
54
|
+
init: {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: {
|
|
57
|
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
58
|
+
Accept: "application/json",
|
|
59
|
+
},
|
|
60
|
+
body,
|
|
61
|
+
},
|
|
62
|
+
policy: { allowedHostnames: [GOOGLE_MEET_TOKEN_HOST] },
|
|
63
|
+
auditContext: "google-meet.oauth.token",
|
|
64
|
+
});
|
|
65
|
+
try {
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const detail = await response.text();
|
|
68
|
+
throw new Error(`Google OAuth token request failed (${response.status}): ${detail}`);
|
|
69
|
+
}
|
|
70
|
+
const payload = (await response.json()) as {
|
|
71
|
+
access_token?: string;
|
|
72
|
+
expires_in?: number;
|
|
73
|
+
refresh_token?: string;
|
|
74
|
+
scope?: string;
|
|
75
|
+
token_type?: string;
|
|
76
|
+
};
|
|
77
|
+
const accessToken = payload.access_token?.trim();
|
|
78
|
+
if (!accessToken) {
|
|
79
|
+
throw new Error("Google OAuth token response was missing access_token");
|
|
80
|
+
}
|
|
81
|
+
const expiresInSeconds =
|
|
82
|
+
typeof payload.expires_in === "number" && Number.isFinite(payload.expires_in)
|
|
83
|
+
? payload.expires_in
|
|
84
|
+
: 3600;
|
|
85
|
+
return {
|
|
86
|
+
accessToken,
|
|
87
|
+
expiresAt: Date.now() + expiresInSeconds * 1000,
|
|
88
|
+
refreshToken: payload.refresh_token?.trim() || undefined,
|
|
89
|
+
scope: payload.scope?.trim() || undefined,
|
|
90
|
+
tokenType: payload.token_type?.trim() || undefined,
|
|
91
|
+
};
|
|
92
|
+
} finally {
|
|
93
|
+
await release();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function tokenRequestBody(values: Record<string, string | undefined>): URLSearchParams {
|
|
98
|
+
const body = new URLSearchParams();
|
|
99
|
+
for (const [key, value] of Object.entries(values)) {
|
|
100
|
+
if (value?.trim()) {
|
|
101
|
+
body.set(key, value);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return body;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function exchangeGoogleMeetAuthCode(params: {
|
|
108
|
+
clientId: string;
|
|
109
|
+
clientSecret?: string;
|
|
110
|
+
code: string;
|
|
111
|
+
verifier: string;
|
|
112
|
+
redirectUri?: string;
|
|
113
|
+
}): Promise<GoogleMeetOAuthTokens> {
|
|
114
|
+
return await executeGoogleTokenRequest(
|
|
115
|
+
tokenRequestBody({
|
|
116
|
+
client_id: params.clientId,
|
|
117
|
+
client_secret: params.clientSecret,
|
|
118
|
+
code: params.code,
|
|
119
|
+
grant_type: "authorization_code",
|
|
120
|
+
redirect_uri: params.redirectUri ?? GOOGLE_MEET_REDIRECT_URI,
|
|
121
|
+
code_verifier: params.verifier,
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function refreshGoogleMeetAccessToken(params: {
|
|
127
|
+
clientId: string;
|
|
128
|
+
clientSecret?: string;
|
|
129
|
+
refreshToken: string;
|
|
130
|
+
}): Promise<GoogleMeetOAuthTokens> {
|
|
131
|
+
return await executeGoogleTokenRequest(
|
|
132
|
+
tokenRequestBody({
|
|
133
|
+
client_id: params.clientId,
|
|
134
|
+
client_secret: params.clientSecret,
|
|
135
|
+
grant_type: "refresh_token",
|
|
136
|
+
refresh_token: params.refreshToken,
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function shouldUseCachedGoogleMeetAccessToken(params: {
|
|
142
|
+
accessToken?: string;
|
|
143
|
+
expiresAt?: number;
|
|
144
|
+
now?: number;
|
|
145
|
+
safetyWindowMs?: number;
|
|
146
|
+
}): boolean {
|
|
147
|
+
const now = params.now ?? Date.now();
|
|
148
|
+
const safetyWindowMs = params.safetyWindowMs ?? 60_000;
|
|
149
|
+
return Boolean(
|
|
150
|
+
params.accessToken?.trim() &&
|
|
151
|
+
typeof params.expiresAt === "number" &&
|
|
152
|
+
Number.isFinite(params.expiresAt) &&
|
|
153
|
+
params.expiresAt > now + safetyWindowMs,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function resolveGoogleMeetAccessToken(params: {
|
|
158
|
+
clientId?: string;
|
|
159
|
+
clientSecret?: string;
|
|
160
|
+
refreshToken?: string;
|
|
161
|
+
accessToken?: string;
|
|
162
|
+
expiresAt?: number;
|
|
163
|
+
}): Promise<{ accessToken: string; expiresAt?: number; refreshed: boolean }> {
|
|
164
|
+
if (shouldUseCachedGoogleMeetAccessToken(params)) {
|
|
165
|
+
return {
|
|
166
|
+
accessToken: params.accessToken!.trim(),
|
|
167
|
+
expiresAt: params.expiresAt,
|
|
168
|
+
refreshed: false,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (!params.clientId?.trim() || !params.refreshToken?.trim()) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
"Missing Google Meet OAuth credentials. Configure oauth.clientId and oauth.refreshToken, or pass --client-id and --refresh-token.",
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
const refreshed = await refreshGoogleMeetAccessToken({
|
|
177
|
+
clientId: params.clientId,
|
|
178
|
+
clientSecret: params.clientSecret,
|
|
179
|
+
refreshToken: params.refreshToken,
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
accessToken: refreshed.accessToken,
|
|
183
|
+
expiresAt: refreshed.expiresAt,
|
|
184
|
+
refreshed: true,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function createGoogleMeetPkce() {
|
|
189
|
+
const { verifier, challenge } = generateHexPkceVerifierChallenge();
|
|
190
|
+
return { verifier, challenge };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function createGoogleMeetOAuthState(): string {
|
|
194
|
+
return generateOAuthState();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export async function waitForGoogleMeetAuthCode(params: {
|
|
198
|
+
state: string;
|
|
199
|
+
manual: boolean;
|
|
200
|
+
timeoutMs: number;
|
|
201
|
+
authUrl: string;
|
|
202
|
+
promptInput: (message: string) => Promise<string>;
|
|
203
|
+
writeLine: (message: string) => void;
|
|
204
|
+
}): Promise<string> {
|
|
205
|
+
params.writeLine(`Open this URL in your browser:\n\n${params.authUrl}\n`);
|
|
206
|
+
if (params.manual) {
|
|
207
|
+
const input = await params.promptInput("Paste the full redirect URL here: ");
|
|
208
|
+
const parsed = parseOAuthCallbackInput(input, {
|
|
209
|
+
missingState: "Missing 'state' parameter. Paste the full redirect URL.",
|
|
210
|
+
invalidInput: "Paste the full redirect URL, not just the code.",
|
|
211
|
+
});
|
|
212
|
+
if ("error" in parsed) {
|
|
213
|
+
throw new Error(parsed.error);
|
|
214
|
+
}
|
|
215
|
+
if (parsed.state !== params.state) {
|
|
216
|
+
throw new Error("OAuth state mismatch - please try again");
|
|
217
|
+
}
|
|
218
|
+
return parsed.code;
|
|
219
|
+
}
|
|
220
|
+
const callback = await waitForLocalOAuthCallback({
|
|
221
|
+
expectedState: params.state,
|
|
222
|
+
timeoutMs: params.timeoutMs,
|
|
223
|
+
port: 8085,
|
|
224
|
+
callbackPath: "/oauth2callback",
|
|
225
|
+
redirectUri: GOOGLE_MEET_REDIRECT_URI,
|
|
226
|
+
successTitle: "Google Meet OAuth complete",
|
|
227
|
+
});
|
|
228
|
+
return callback.code;
|
|
229
|
+
}
|