Skip to content

Commit

Permalink
Adds authentication support for the extension in playground environme…
Browse files Browse the repository at this point in the history
…nts (stateful#1759)

Adds authentication support for the extension in playground environments, integrating cloud token validation and enabling token retrieval from callback URLs dispatched by the cloud. Key changes include:

- **Auth Token Handling:** Simplified by removing unused refresh token logic, as the access-token has an extended lifespan.
- **Load from Secrets:** An instance method now checks tokens against playground secrets, using the cloud endpoint for validation.
- **Callback Integration:** Supports token recovery from cloud callback URLs, enhancing seamless access when the user is already Authenticated in the Cloud.

---------

Co-authored-by: Sebastian Tiedtke <sebastiantiedtke@gmail.com>
  • Loading branch information
2 people authored and hotpocket committed Nov 5, 2024
1 parent c8cb5e7 commit f0525a6
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 120 deletions.
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,11 +966,6 @@
"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.serializerAddress": {
"type": "string",
"default": "http://localhost:1234/connect",
Expand All @@ -981,6 +976,20 @@
"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 @@ -1231,6 +1240,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 @@ -1312,6 +1322,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 @@ -474,31 +473,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

0 comments on commit f0525a6

Please sign in to comment.