feat: migrate API key storage to Obsidian's secure SecretStorage - #2
feat: migrate API key storage to Obsidian's secure SecretStorage#2jcmexdev wants to merge 1 commit into
Conversation
|
I would have thought that the Obsidian version in |
Ah no, this probably came from the Sample Plugin, which just uses Obsidian So the But that would all depend on on if @stroiman were still supporting this plugin... |
|
Hey, thanks for providing this suggestion. I didn't see this until now, but I'll check it out. |
| import Publisher from "src/publisher"; | ||
|
|
||
| interface DevPublishPluginSessings { | ||
| interface DevPublishPluginSettings { |
There was a problem hiding this comment.
Nice to fix the typo, but it appears to me this type doesn't have any relevance anymore?
There was a problem hiding this comment.
I fixed the typo because the type is still relevant to store the secret identifier chosen by the user.
Since the user picks or creates their own secret key from the vault, we can't hardcode a default. We must save this custom key ID in settings.apiKey so we know which secret to retrieve from Obsidian's secure storage (SecretStorage).
Let me know if you see a better way to handle this, or if this approach looks good to you!
There was a problem hiding this comment.
Cool, thanks for the feedback - I was just quickly glancing through the changes, when it caught my eye. I'll give it a more detailed look when I have time.
| @@ -107,17 +121,16 @@ class DevPublishSettingTab extends PluginSettingTab { | |||
| .setName("API key") | |||
| .setDesc( | |||
| sanitizeHTMLToDom( | |||
There was a problem hiding this comment.
Totally makes sense! I forgot to remove the sanitizer when I simplified the text. I'll update it to just use the plain string.
Summary
This Pull Request addresses the security limitation of storing the DEV.to API key in plain text in the plugin's
data.jsonfile. It migrates the credential storage to use Obsidian's nativeSecretStorageAPI (introduced in Obsidian v1.11.4), which integrates securely with the operating system's keychain.This fulfills the essential feature requested in the roadmap:
Key Changes
Secure API Key Management (
main.ts)SecretStorageflow viaSecretComponentto let users create/select a secure vault secret.getApiKey()helper method, ensuring the real API key is fetched at runtime fromapp.secretStorage.getSecretrather than being saved in plain text insidedata.json.map-image-filesandpublish-current-note) to use the new validation helper, following the DRY principle.Documentation Update (
README.md)Typo Correction (
main.ts)DevPublishPluginSessingstoDevPublishPluginSettings.Verification
npm run testsuccessfully with all 38 tests passing.npm run build(esbuildbundler).data.jsonand the actual key is retrieved securely through the Obsidian app.