MCPcopy Create free account
hub / github.com/anus-dev/ANUS / authWithUserCode

Function authWithUserCode

packages/core/src/code_assist/oauth2.ts:203–247  ·  view source on GitHub ↗
(client: OAuth2Client)

Source from the content-addressed store, hash-verified

201}
202
203async function authWithUserCode(client: OAuth2Client): Promise<boolean> {
204 const redirectUri = 'https://codeassist.google.com/authcode';
205 const codeVerifier = await client.generateCodeVerifierAsync();
206 const state = crypto.randomBytes(32).toString('hex');
207 const authUrl: string = client.generateAuthUrl({
208 redirect_uri: redirectUri,
209 access_type: 'offline',
210 scope: OAUTH_SCOPE,
211 code_challenge_method: CodeChallengeMethod.S256,
212 code_challenge: codeVerifier.codeChallenge,
213 state,
214 });
215 console.log('Please visit the following URL to authorize the application:');
216 console.log('');
217 console.log(authUrl);
218 console.log('');
219
220 const code = await new Promise<string>((resolve) => {
221 const rl = readline.createInterface({
222 input: process.stdin,
223 output: process.stdout,
224 });
225 rl.question('Enter the authorization code: ', (code) => {
226 rl.close();
227 resolve(code.trim());
228 });
229 });
230
231 if (!code) {
232 console.error('Authorization code is required.');
233 return false;
234 }
235
236 try {
237 const { tokens } = await client.getToken({
238 code,
239 codeVerifier: codeVerifier.codeVerifier,
240 redirect_uri: redirectUri,
241 });
242 client.setCredentials(tokens);
243 } catch (_error) {
244 return false;
245 }
246 return true;
247}
248
249async function authWithWeb(client: OAuth2Client): Promise<OauthWebLogin> {
250 const port = await getAvailablePort();

Callers 1

initOauthClientFunction · 0.85

Calls 2

closeMethod · 0.80
getTokenMethod · 0.80

Tested by

no test coverage detected