Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds authentication support for the extension in playground environments #1759

Merged
merged 15 commits into from
Oct 31, 2024
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ examples/.vscode
assets
.venv
**/*-01*.md
secrets
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ tests
coverage
dagger
dagger.json
secrets
37 changes: 20 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -966,16 +966,25 @@
"default": true,
"markdownDescription": "If set to `true` enables Stateful Authentication Provider"
},
"runme.aiBaseURL": {
"type": "string",
"default": "http://localhost:8877/api",
"description": "The base URL of the AI service."
},
"runme.app.docsUrl": {
"type": "string",
"scope": "window",
"default": "https://docs.runme.dev",
"markdownDescription": "Documentation Base URL"
},
"runme.app.authTokenPath": {
"type": "string",
"markdownDescription": "Specifies the path to an auth token file to bootstrap a Stateful auth session"
},
"runme.app.deleteAuthToken": {
"type": "boolean",
"default": true,
"markdownDescription": "If set to `true`, the auth token file will be deleted after the session ends"
},
"runme.aiBaseURL": {
"type": "string",
"default": "http://localhost:8877/api",
"description": "The base URL of the AI service."
}
}
}
Expand Down Expand Up @@ -1226,6 +1235,7 @@
"@graphql-codegen/client-preset": "^4.4.0",
"@graphql-codegen/typescript": "4.1.0",
"@octokit/rest": "^19.0.13",
"@types/jsonwebtoken": "^9.0.7",
"@types/node": "^20.17.2",
"@types/node-fetch": "^2.6.11",
"@types/semver": "^7.5.8",
Expand Down Expand Up @@ -1307,6 +1317,7 @@
"got": "^11.8.2",
"graphql": "^16.8.0",
"jsonc-parser": "^3.2.1",
"jsonwebtoken": "^9.0.2",
"lit": "^3.2.1",
"octokit": "^4.0.2",
"simple-git": "^3.27.0",
Expand Down
26 changes: 12 additions & 14 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { NotebookUiEvent, Serializer, SyncSchema, FeatureName } from '../types'
import {
getDocsUrlFor,
getForceNewWindowConfig,
getRunmeAppUrl,
getServerRunnerVersion,
getSessionOutputs,
getServerLifecycleIdentity,
Expand Down Expand Up @@ -467,31 +466,30 @@ export class RunmeExtension {
}

if (kernel.isFeatureOn(FeatureName.RequireStatefulAuth)) {
const forceLogin = kernel.isFeatureOn(FeatureName.ForceLogin)
context.subscriptions.push(new StatefulAuthProvider(context, uriHandler))
const statefulAuthProvider = new StatefulAuthProvider(context, uriHandler)
context.subscriptions.push(statefulAuthProvider)

const session = await getPlatformAuthSession(false, true)
let sessionFromToken = false
if (!session) {
sessionFromToken = await statefulAuthProvider.bootstrapFromToken()
}

const forceLogin = kernel.isFeatureOn(FeatureName.ForceLogin) || sessionFromToken
const silent = forceLogin ? undefined : true

getPlatformAuthSession(forceLogin, silent)
.then((session) => {
if (session) {
const openDashboardStr = 'Open Dashboard'
window
.showInformationMessage('Logged into the Stateful Platform', openDashboardStr)
.then((answer) => {
if (answer === openDashboardStr) {
const dashboardUri = getRunmeAppUrl(['app'])
const uri = Uri.parse(dashboardUri)
env.openExternal(uri)
}
})
statefulAuthProvider.showLoginNotification()
}
})
.catch((error) => {
let message
if (error instanceof Error) {
message = error.message
} else {
message = String(error)
message = JSON.stringify(error)
}

// https://github.com/microsoft/vscode/blob/main/src/vs/workbench/api/browser/mainThreadAuthentication.ts#L238
Expand Down
Loading