mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Dev (#77)
* Fix git credential saving and improve host matching - Fix token masking bug in GitCredentialDialog that corrupted tokens on edit - Add tokenEdited state to preserve original token when not modified - Default new credential host to https://github.com - Add normalizeHostname helper for consistent host comparison - Improve credential lookup logging to show configured vs requested hosts - Remove overly permissive fuzzy matching that could leak tokens * Make OpenCode reload non-fatal when saving git credentials Settings are now saved to database even if the OpenCode server reload fails. The reload error is returned separately so the UI can inform the user that credentials were saved but the server needs a manual restart. * Fix git fetch using credentials in silent mode Previously, silent mode (used for UI fetch operations) would skip credential lookup entirely and return empty, causing auth failures. Now credentials are always looked up via IPC regardless of silent mode.
This commit is contained in:
1 parent
3a8d4993c1
commit
24aa4f6c83
6 files changed
+80
-39
No files matched your search
@@ -88,34 +88,50 @@ export class AskpassHandler implements IPCHandler {
|
||||
return ''
|
||||
}
|
||||
|
||||
private normalizeHostname(host: string): string {
|
||||
let normalized = host.toLowerCase().trim()
|
||||
normalized = normalized.replace(/\/+$/, '')
|
||||
|
||||
if (!normalized.includes('://')) {
|
||||
normalized = 'https://' + normalized
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = new URL(normalized)
|
||||
return parsed.hostname
|
||||
} catch {
|
||||
const stripped = normalized.replace(/^https?:\/\//, '')
|
||||
return stripped.split('/')[0] || stripped
|
||||
}
|
||||
}
|
||||
|
||||
private async getCredentialsForHost(hostname: string): Promise<Credentials | null> {
|
||||
logger.info(`Looking up credentials for host: ${hostname}`)
|
||||
const normalizedRequest = this.normalizeHostname(hostname)
|
||||
logger.info(`Looking up credentials for host: ${hostname} (normalized: ${normalizedRequest})`)
|
||||
|
||||
const settingsService = new SettingsService(this.database)
|
||||
const settings = settingsService.getSettings('default')
|
||||
const gitCredentials: GitCredential[] = settings.preferences.gitCredentials || []
|
||||
logger.info(`Found ${gitCredentials.length} configured git credentials`)
|
||||
|
||||
for (const cred of gitCredentials) {
|
||||
try {
|
||||
const parsed = new URL(cred.host)
|
||||
if (parsed.hostname.toLowerCase() === hostname.toLowerCase()) {
|
||||
logger.info(`Found matching credential for ${hostname}`)
|
||||
return {
|
||||
username: cred.username || this.getDefaultUsername(cred.host),
|
||||
password: cred.token,
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
if (cred.host.toLowerCase().includes(hostname.toLowerCase())) {
|
||||
logger.info(`Found matching credential (fuzzy match) for ${hostname}`)
|
||||
return {
|
||||
username: cred.username || 'oauth2',
|
||||
password: cred.token,
|
||||
}
|
||||
const normalizedCred = this.normalizeHostname(cred.host)
|
||||
logger.debug(`Comparing: request='${normalizedRequest}' vs stored='${normalizedCred}' (raw: ${cred.host})`)
|
||||
|
||||
if (normalizedCred === normalizedRequest) {
|
||||
logger.info(`Found matching credential '${cred.name}' for ${hostname}`)
|
||||
return {
|
||||
username: cred.username || this.getDefaultUsername(cred.host),
|
||||
password: cred.token,
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.warn(`No credentials found for host: ${hostname}`)
|
||||
|
||||
if (gitCredentials.length > 0) {
|
||||
logger.warn(`No credentials found for host: ${hostname}. Configured hosts: ${gitCredentials.map(c => c.host).join(', ')}`)
|
||||
} else {
|
||||
logger.warn(`No credentials found for host: ${hostname}. No git credentials configured.`)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user