Draft
Conversation
Comment on lines
+352
to
+363
| app.get('/auth/login', (req, res) => { | ||
| if (!OAUTH_ENABLED) return res.status(404).json({ error: oauthUnavailableMessage() }); | ||
| const state = crypto.randomBytes(16).toString('hex'); | ||
| req.session.oauthState = state; | ||
| const params = new URLSearchParams({ | ||
| client_id: GITHUB_CLIENT_ID, | ||
| redirect_uri: `${req.protocol}://${req.get('host')}/auth/callback`, | ||
| scope: 'read:user', | ||
| state, | ||
| }); | ||
| res.redirect(`https://github.com/login/oauth/authorize?${params}`); | ||
| }); |
Comment on lines
+366
to
+404
| app.get('/auth/callback', async (req, res) => { | ||
| if (!OAUTH_ENABLED) return res.status(404).json({ error: oauthUnavailableMessage() }); | ||
| const { code, state } = req.query; | ||
| if (!code || !state || state !== req.session.oauthState) { | ||
| return res.status(400).send('Invalid OAuth callback. <a href="/">Go back</a>'); | ||
| } | ||
| delete req.session.oauthState; | ||
| try { | ||
| // Exchange code for access token | ||
| const tokenRes = await fetch('https://github.com/login/oauth/access_token', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, | ||
| body: JSON.stringify({ | ||
| client_id: GITHUB_CLIENT_ID, | ||
| client_secret: GITHUB_CLIENT_SECRET, | ||
| code, | ||
| }), | ||
| }); | ||
| const tokenData = await tokenRes.json(); | ||
| if (tokenData.error) throw new Error(tokenData.error_description || tokenData.error); | ||
| // Fetch user profile | ||
| const userRes = await fetch('https://api.github.com/user', { | ||
| headers: { Authorization: `Bearer ${tokenData.access_token}`, Accept: 'application/json' }, | ||
| }); | ||
| if (!userRes.ok) throw new Error(`GitHub API error: ${userRes.status}`); | ||
| const user = await userRes.json(); | ||
| req.session.user = { | ||
| id: String(user.id), | ||
| login: user.login, | ||
| name: user.name || user.login, | ||
| avatar: user.avatar_url, | ||
| }; | ||
| console.log(`[Auth] GitHub login: ${user.login}`); | ||
| res.redirect('/'); | ||
| } catch (err) { | ||
| console.error('[Auth] OAuth error:', err.message); | ||
| res.status(500).send(`Login failed: ${err.message}. <a href="/">Go back</a>`); | ||
| } | ||
| }); |
Comment on lines
+1287
to
+1297
| app.use(session({ | ||
| secret: process.env.SESSION_SECRET || crypto.randomBytes(32).toString('hex'), | ||
| resave: false, | ||
| saveUninitialized: false, | ||
| cookie: { | ||
| secure: process.env.NODE_ENV === 'production', | ||
| httpOnly: true, | ||
| maxAge: 24 * 60 * 60 * 1000, | ||
| sameSite: 'lax', | ||
| }, | ||
| })); |
|
|
||
| async function runCommandOrThrow(command, args = []) { | ||
| const launch = resolveSpawnLaunch(command, args); | ||
| const child = spawn(launch.command, launch.args, { stdio: 'inherit', shell: false }); |
Comment on lines
+329
to
+333
| const child = spawn(resolvedLaunch.command, resolvedLaunch.args, { | ||
| stdio: ['pipe', 'pipe', 'pipe'], | ||
| env: { ...process.env, ...(ACP_AGENTS[agentName]?.env || {}) }, | ||
| shell: false, | ||
| }); |
cf5072f to
0363b55
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.