Skip to content

Store API tokens in Obsidian Keychain#178

Open
jdevera wants to merge 5 commits into
nathonius:mainfrom
jdevera:feat/obsidian-keychain
Open

Store API tokens in Obsidian Keychain#178
jdevera wants to merge 5 commits into
nathonius:mainfrom
jdevera:feat/obsidian-keychain

Conversation

@jdevera
Copy link
Copy Markdown

@jdevera jdevera commented Apr 17, 2026

Summary

Resolves #177

Uses the Obsidian SecretStorage API (introduced in v1.11.4) to store GitHub tokens in the OS keychain (macOS Keychain, Windows Credential Manager, Linux libsecret) instead of plain text in data.json.

  • Tokens are stored and retrieved via a new keychain.ts module
  • Existing plain-text tokens are automatically migrated to the keychain on first load after update
  • Tokens are stripped from data.json on every save
  • Deleting an account clears the token value from the keychain (the SecretStorage API does not support deleting entries, only clearing them)
  • minAppVersion bumped to 1.11.4

What I have tested

  • Fresh install: create a new account with a token, verify it appears in Obsidian's Keychain settings and data.json has an empty token field
  • Migration: start with an existing data.json containing a plain-text token (dataVersion 1), reload, verify the token moves to keychain and data.json token is cleared
  • Token still works: after migration, verify GitHub links in notes still resolve
  • Account deletion: delete an account, verify its keychain value is cleared
  • OAuth flow: generate a token via the OAuth device flow, verify it lands in the keychain

jdevera added 3 commits April 17, 2026 19:12
Use the SecretStorage API (Obsidian 1.11.4+) to store GitHub tokens
in the OS keychain instead of plain text in data.json.

- Add keychain module with clear token CRUD operations
- Automatically migrate existing plain-text tokens on first load
- Strip tokens from data.json on every save
- Bump DATA_VERSION to 2 and minAppVersion to 1.11.4
Update obsidian package to latest for SecretStorage types.
Add missing members to test mocks for API compatibility.
Avoids SonarCloud S1186 (unexpected empty method).
@jdevera jdevera force-pushed the feat/obsidian-keychain branch from 02aea5a to b477774 Compare April 17, 2026 18:25
@jdevera jdevera marked this pull request as draft April 18, 2026 21:04
@jdevera
Copy link
Copy Markdown
Author

jdevera commented Apr 18, 2026

Reworking this to be more idiomatic with Obsidian's SecretStorage API:

  • Use SecretComponent (via Setting.addComponent) to let users pick/create named secrets through Obsidian's built-in UI, instead of managing secret keys directly
  • Store the secret name in settings (tokenSecret) rather than the value — the actual token is read at runtime via app.secretStorage.getSecret(name)
  • This aligns with how other plugins (Enveloppe, QuickAdd, BRAT, etc.) use the API, and lets users share secrets across plugins

Converting to draft while I rework.

@jdevera jdevera marked this pull request as ready for review April 18, 2026 21:44
jdevera added 2 commits April 18, 2026 23:59
Switch to Obsidian's built-in SecretComponent UI widget for token
selection, letting users pick or create named secrets through the
standard Obsidian keychain interface.

- Add tokenSecret field to GithubAccount to store the secret name
- Replace plain text token input with SecretComponent via addComponent
- Auto-generate secret names from account name during migration
- Read token values at runtime via secretStorage.getSecret(tokenSecret)
@jdevera jdevera force-pushed the feat/obsidian-keychain branch from 7429759 to 52bece2 Compare April 18, 2026 23:00
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Obsidian Keychain

1 participant