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

Test: Proposed API getAccounts API & AuthenticationProvider changes #216836

Closed
2 tasks done
TylerLeonhardt opened this issue Jun 21, 2024 · 2 comments
Closed
2 tasks done

Comments

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Jun 21, 2024

Refs: #152399

Complexity: 5

Create Issue


This iteration we've moved away from the previous proposed getSessions API... to something that separates the concept of "Accounts" and "Sessions".

An "Account" is basically an identity, without access to anything. It just says who you are... while a "Session", on the other hand, has an accessToken that can access whatever scopes were requested. This also means that the concept of scopes doesn't matter to an "Account"... and scopes only matter to "session".

Put plainly, 1 account can have multiple sessions tied to it.

Next context! An AuthenticationProvider can be marked as supporting only 1 account or multiple accounts at a time. For this TPI, it's really only applicable when you support multiple accounts so make sure you do that.

Alright, enough chat... let's test.

Prereqs

  • Have an extension (don't have one? create one!)
  • Add the proposed API in the package.json:
    "enabledApiProposals": ["authGetSessions"],
  • Run npx @vscode/dts dev to get the proposed API file

Implement an Authentication Provider

You'll want to:

  • Contribute an Auth Provider in the authentication contribution section of the package.json
  • Then register an Auth Provider using:
    vscode.authentication.registerAuthenticationProvider(id, name, yourAuthProvider, { supportsMultipleAccounts: true });

You can absolutely attempt to implement a full auth provider if you'd like... I'm not gonna stop you :) Here's what my Spotify one looks like (but it's not multi-account).

But it's not necessary. Having getSessions and createSession return dummy data is totally fine for this TPI. Just make sure you test having it:

  • return zero sessions (which cases createSession to run)
  • return 1 or many sessions but of only 1 account
  • return several sessions with different accounts

The important part is having getSessions and createSession take in the new:

	export interface AuthenticationProviderSessionOptions {
		/**
		 * The account that is being asked about. If this is passed in, the provider should
		 * attempt to return the sessions that are only related to this account.
		 */
		account?: AuthenticationSessionAccountInformation;
	}

and do something with it. This property will be used to filter down the list of sessions we have to only the account passed in or used to create a session specific to that account.

Once you have an Auth Provider, it's time to use it.

Implement something that uses the new getAccounts & additions to getSession API

Now time for the consumer! (you can do this in the same extension via a Command or something)

Play around with the vscode.authentication.getAccounts API which should return all accounts that you are logged in to.

Additionally, play around with passing an account returned by that API into vscode.authentication.getSession via the options.

@sandy081
Copy link
Member

Tested this by implementing an auth provider for Slack with multiple accounts. All APIs seems to work as expected.

@sandy081 sandy081 removed their assignment Jun 25, 2024
@bhavyaus
Copy link
Collaborator

Reused the auth provider sample and signed into multiple Azure Dev ops accounts.

@bhavyaus bhavyaus removed their assignment Jun 25, 2024
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants