Skip to content

Commit 2c9ba65

Browse files
committed
temp: everything auth related (TODO: don't hardcode)
1 parent 1f55f8f commit 2c9ba65

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
{
3232
"command": "source-academy.eval-editor",
3333
"title": "Source Academy: Run Code in Editor"
34+
},
35+
{
36+
"command": "source-academy.login",
37+
"title": "Source Academy: Login"
3438
}
3539
],
3640
"configuration": {

src/commands/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from "vscode";
22
import { runLanguagePicker } from "./language";
33
import { evalEditor } from "./evalEditor";
44
import { showPanel } from "./showPanel";
5+
import { login } from "./login";
56

67
const EXTENSION_ID = "source-academy";
78

@@ -12,6 +13,7 @@ const EXTENSION_ID = "source-academy";
1213
const commands = (context: vscode.ExtensionContext) => ({
1314
pick: () => runLanguagePicker(context),
1415
"show-panel": () => showPanel(context),
16+
login: () => login(context),
1517
"eval-editor": () => evalEditor(context),
1618
});
1719

src/commands/login.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as vscode from "vscode";
2+
3+
export async function login(context: vscode.ExtensionContext) {
4+
vscode.env.openExternal(
5+
vscode.Uri.parse(
6+
// "http://localhost:4000/sso/auth/signin/student?target_url=http://localhost:4000/v2/auth/saml_redirect?provider=test_saml_vscode",
7+
"http://localhost:4000/sso/auth/signin/student?target_url=http://localhost:4000/v2/auth/saml_redirect_vscode?provider=test_saml",
8+
),
9+
);
10+
// vscode.env.openExternal(vscode.Uri.parse('http://localhost:4000/sso/auth/signin/student?target_url=http://example.com'));
11+
}

src/commands/showPanel.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,23 @@ async function handleMessage(
3636
console.log(`${Date.now()} Beginning handleMessage: ${message.type}`);
3737
switch (message.type) {
3838
case MessageTypeNames.ExtensionPing:
39-
sendToFrontend(panel, Messages.ExtensionPong(null));
39+
let state = context.globalState.get("token") ?? null;
40+
41+
const token = state ? JSON.stringify(state) : null;
42+
43+
console.log(`WebviewStarted: Obtain token from VSC: ${token}`);
44+
45+
// if (token !== null && Object.keys(token).length === 0) {
46+
// token = null
47+
// }
48+
// if (token !== null) {
49+
// token = JSON.stringify(token);
50+
// }
51+
52+
panel!.webview.postMessage(Messages.ExtensionPong(token));
53+
if (token) {
54+
context.globalState.update("token", undefined);
55+
}
4056
break;
4157
case MessageTypeNames.NewEditor:
4258
activeEditor = await Editor.create(
@@ -56,8 +72,10 @@ async function handleMessage(
5672
}
5773
if (editor !== activeEditor) {
5874
console.log(
59-
`EXTENSION: Editor ${editor.assessmentName}_${editor.questionId} is no longer active, skipping onChange`,
75+
`EXTENSION: Editor is no longer active, skipping onChange`,
76+
`User edited ${editor.assessmentName}_${editor.questionId}, active is ${activeEditor?.assessmentName}_${activeEditor?.questionId}`,
6077
);
78+
return;
6179
}
6280
const message = Messages.Text(workspaceLocation, code);
6381
console.log(`Sending message: ${JSON.stringify(message)}`);
@@ -78,7 +96,8 @@ async function handleMessage(
7896
handling = false;
7997
}
8098

81-
export async function showPanel(context: vscode.ExtensionContext) {
99+
export async function showPanel(context: vscode.ExtensionContext, url: string) {
100+
vscode.window.showInformationMessage(`showPanel caleld with ${url}`);
82101
let language: string | undefined = context.workspaceState.get("language");
83102
if (!language) {
84103
language = LANGUAGES.SOURCE_1;
@@ -117,7 +136,8 @@ export async function showPanel(context: vscode.ExtensionContext) {
117136
>
118137
<iframe
119138
id={FRONTEND_ELEMENT_ID}
120-
src={frontendUrl}
139+
src={url || frontendUrl}
140+
// src={"vscode://source-academy.source-academy/sso"}
121141
width="100%"
122142
height="100%"
123143
// @ts-ignore

src/extension.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Import the module and reference it with the alias vscode in your code below
33
import * as vscode from "vscode";
44
import { setupStatusBar } from "./statusbar/status";
5-
import { evalEditor } from "./commands/evalEditor";
65
import { registerAllCommands } from "./commands";
76
import { activateLspClient, deactivateLspClient } from "./lsp/client";
7+
import { showPanel } from "./commands/showPanel";
88

99
// This method is called when your extension is activated
1010
// Your extension is activated the very first time the command is executed
@@ -14,6 +14,22 @@ export function activate(context: vscode.ExtensionContext) {
1414
context.subscriptions.push(setupStatusBar(context));
1515

1616
activateLspClient(context);
17+
vscode.window.registerUriHandler({
18+
handleUri(uri: vscode.Uri) {
19+
const searchParams = new URLSearchParams(uri.query);
20+
const code = searchParams.get("code");
21+
vscode.window.showInformationMessage(`Code: ${code}`);
22+
const provider = searchParams.get("provider");
23+
vscode.window.showInformationMessage(`Provider: ${provider}`);
24+
25+
// context.globalState.update("token", {
26+
// accessToken: code,
27+
// refreshToken: provider,
28+
// });
29+
const url = `http://localhost:4000/v2/auth/exchange/?code=${code}&provider=${provider}`;
30+
showPanel(context, url);
31+
},
32+
});
1733
}
1834

1935
// This method is called when your extension is deactivated

0 commit comments

Comments
 (0)