Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secrets API #112249

Closed
RMacfarlane opened this issue Dec 10, 2020 · 6 comments
Closed

Secrets API #112249

RMacfarlane opened this issue Dec 10, 2020 · 6 comments
Assignees
Labels
api-finalization insiders-released Patch has been released in VS Code Insiders
Milestone

Comments

@RMacfarlane
Copy link
Contributor

A couple of months ago we introduced password related APIs that are currently being used by the built-in auth provider extensions. These APIs expose a first-class way for extensions to store sensitive information, instead of having to use a library like keytar themselves. The API currently looks like:

		/**
		 * Retrieve a password that was stored with key. Returns undefined if there
		 * is no password matching that key.
		 * @param key The key the password was stored under.
		 */
		export function getPassword(key: string): Thenable<string | undefined>;

		/**
		 * Store a password under a given key.
		 * @param key The key to store the password under
		 * @param value The password
		 */
		export function setPassword(key: string, value: string): Thenable<void>;

		/**
		 * Remove a password from storage.
		 * @param key The key the password was stored under.
		 */
		export function deletePassword(key: string): Thenable<void>;

		/**
		 * Fires when a password is set or deleted.
		 */
		export const onDidChangePassword: Event<void>;

Some suggestions that I plan to adopt are

  • move to the extension context instead of the authentication namespace, as what's being stored is not necessarily auth info, and these APIs are similar to the storage APIs on context
  • rename to secret instead of password, also to make it more generic
@RMacfarlane
Copy link
Contributor Author

I have moved this over to the extension context, it now looks like:

	export interface SecretState {
		/**
		 * Retrieve a secret that was stored with key. Returns undefined if there
		 * is no password matching that key.
		 * @param key The key the password was stored under.
		 */
		get(key: string): Thenable<string | undefined>;

		/**
		 * Store a secret under a given key.
		 * @param key The key to store the password under
		 * @param value The password
		 */
		set(key: string, value: string): Thenable<void>;

		/**
		 * Remove a secret from storage.
		 * @param key The key the password was stored under.
		 */
		delete(key: string): Thenable<void>;

		/**
		 * Fires when a secret is set or deleted.
		 */
		onDidChange: Event<void>;
	}

	export interface ExtensionContext {
		secretState: SecretState;
	}

@ankitbko
Copy link
Member

ankitbko commented Jan 13, 2021

  1. Is the secret scoped to a particular extension or can any extension read the secrets?
  2. Does the key need to be unique within an extension or globally unique?

@RMacfarlane
Copy link
Contributor Author

RMacfarlane commented Jan 13, 2021 via email

@ankitbko
Copy link
Member

Thanks, is there any way to know which secret was set or deleted in onDidChange: Event<void>?

@ankitbko
Copy link
Member

@RMacfarlane So the event does not pass any argument so there does not looks like a way to get which key changed. Any chance to implementing this?

@RMacfarlane
Copy link
Contributor Author

Yes, this is something I plan to add today. Should look like

export interface SecretStorageChangeEvent {
    key: string
}
...
onDidChange: Event<SecretStorageChangeEvent>

RMacfarlane pushed a commit that referenced this issue Jan 20, 2021
@RMacfarlane RMacfarlane mentioned this issue Jan 26, 2021
3 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-finalization insiders-released Patch has been released in VS Code Insiders
Projects
None yet
Development

No branches or pull requests

3 participants
@ankitbko @RMacfarlane and others