JuliaHub VS Code Authentication
Authentication extension for JuliaHub package servers in VS Code.
Overview
This extension provides authentication capabilities for JuliaHub package servers, allowing other VS Code extensions to authenticate users and obtain access tokens programmatically.
Requirements
This extension requires the Julia VS Code extension to be installed.
Usage
Commands
The extension provides two commands accessible via the Command Palette (Ctrl+Shift+P / Cmd+Shift+P):
JuliaHub: Log in
Authenticates with the configured JuliaHub server. If you're already authenticated with a valid token, this command will reuse the existing token.
JuliaHub: Log in with new user
Forces a new authentication flow, allowing you to log in with a different user account. This will discard any existing tokens.
Configuration
The extension uses the julia.packageServer configuration setting from the Julia extension to determine which server to authenticate against. If not set, it defaults to the JULIA_PKG_SERVER environment variable or https://juliahub.com.
API for Extension Developers
This extension exports an API that other extensions can use for authentication:
interface ExtensionAPI {
version: number
getJuliaHubServer: () => string
onDidChangeServer: vscode.Event<string>
authenticate: (server?: string, force?: boolean) => Promise<string>
}
Example Usage
// Get the authentication extension
const authExtension = vscode.extensions.getExtension('JuliaComputing.juliahub-vscode-auth')
if (authExtension) {
const authApi = authExtension.exports
// Get the current server
const server = authApi.getJuliaHubServer()
// Authenticate and get token
try {
const token = await authApi.authenticate()
console.log('Successfully authenticated!')
// Use the token for API requests
} catch (error) {
console.error('Authentication failed:', error)
}
// Listen for server changes
authApi.onDidChangeServer((newServer) => {
console.log(`Server changed to: ${newServer}`)
})
}
API Methods
getJuliaHubServer(): string
Returns the currently configured JuliaHub server URL.
authenticate(server?: string, force?: boolean): Promise<string>
Authenticates with the specified server (or the configured server if not provided).
server (optional): The server URL to authenticate against. If undefined, looks at julia.packageServer, JULIA_PKG_SERVER, and finally falls back to juliahub.com
force (optional): If true, forces a new authentication flow even if a valid token exists. Default: false
- Returns: A promise that resolves to the access token string
- Throws:
AuthenticationError(reason, server) if authentication fails
onDidChangeServer: Event<string>
An event that fires when the package server configuration changes. Subscribe to this event to be notified when users change their server settings.
License
See LICENSE file for details.