Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Khare <[email protected]>
  • Loading branch information
khareyash05 committed Sep 9, 2024
1 parent 13d5109 commit 256c390
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 88 deletions.
68 changes: 0 additions & 68 deletions src/SignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,76 +128,8 @@ export default async function SignInWithGitHub() {
SentryInstance?.captureException(error);
}
}


export async function SignInWithOthers() {
try{

const state = generateRandomState(); // Generate a secure random state
const authUrl = `http://localhost:3000/signin?vscode=true&state=${state}`;
vscode.env.openExternal(vscode.Uri.parse(authUrl));

return new Promise((resolve, reject) => {
const server = http.createServer(async (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
res.writeHead(200);
res.end();
return;
}

if (req && req.url && req.url.startsWith('/login/keploy/callback')) {
const url = new URL(req.url, `http://${req.headers.host}`);
const receivedState = url.searchParams.get('state');
const token = url.searchParams.get('token');
console.log("Received state:", receivedState);
console.log("Received token:", token);

if (!receivedState || !token) {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Missing state or token' }));
reject(new Error('Missing state or token'));
server.close();
return;
}

try {
// Simulate processing the token
console.log("Processing token...");

res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'Token received and processed', token, receivedState }));

// Resolve the promise with the token
resolve(token.toString());
} catch (err) {
console.error('Error processing token:', err);
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Internal Server Error' }));
reject(err);
} finally {
server.close(); // Close the server once the request is handled
}
} else {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Not Found' }));
}
}).listen(3001, () => {
console.log('Server listening on port 3001');
});
});
}
catch(error){
console.log(error);
vscode.window.showErrorMessage('Error occurred while signing in with Others');
SentryInstance?.captureException(error);
}
}



export async function SignInWithOthers() {
const state = generateRandomState(); // Generate a secure random state
const authUrl = `http://localhost:3000/signin?vscode=true&state=${state}`;
Expand Down
20 changes: 0 additions & 20 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,6 @@ export function activate(context: vscode.ExtensionContext) {
}
});

let signInWithOthersCommand = vscode.commands.registerCommand('keploy.SignInWithOthers', async () => {
try {
const result = await SignInWithOthers();
const accessToken = result as string; // Assert that result is a string
getInstallationID();
await context.globalState.update('accessToken', accessToken);
if (Boolean(accessToken)) {
vscode.window.showInformationMessage('You are now signed in!');
vscode.commands.executeCommand('setContext', 'keploy.signedIn', true);
vscode.commands.executeCommand('setContext', 'keploy.signedOut', false);
} else {
console.log('Validation failed for the user !');
vscode.window.showInformationMessage('Failed to sign in Keploy!');
}
} catch (error) {
SentryInstance?.captureException(error);
vscode.window.showInformationMessage('Failed to sign in Keploy!');
}
});

let signInWithOthersCommand = vscode.commands.registerCommand('keploy.SignInWithOthers', async () => {
try {
const result = await SignInWithOthers();
Expand Down

0 comments on commit 256c390

Please sign in to comment.