Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extensions/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"activationEvents": [
"onStartupFinished",
"onAuthenticationRequest:anthropic-api",
"onAuthenticationRequest:posit-ai",
"onAuthenticationRequest:ms-foundry",
"onAuthenticationRequest:amazon-bedrock",
"onCommand:authentication.configureProviders",
Expand All @@ -27,6 +28,10 @@
"id": "anthropic-api",
"label": "Anthropic"
},
{
"id": "posit-ai",
"label": "Posit AI"
},
{
"id": "ms-foundry",
"label": "Microsoft Foundry"
Expand Down
9 changes: 8 additions & 1 deletion extensions/authentication/src/authProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ export class AuthProvider
constructor(
private readonly providerId: string,
private readonly displayName: string,
private readonly context: vscode.ExtensionContext,
protected readonly context: vscode.ExtensionContext,
private readonly workbench?: WorkbenchCredentialConfig,
private readonly credentialChain?: CredentialChainConfig,
) { }

/** Expose session-change events to subclasses. */
protected fireSessionsChanged(
event: vscode.AuthenticationProviderAuthenticationSessionsChangeEvent
): void {
this._onDidChangeSessions.fire(event);
}

dispose(): void {
this._disposed = true;
this.stopRefreshTimer();
Expand Down
20 changes: 15 additions & 5 deletions extensions/authentication/src/configDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as vscode from 'vscode';
import * as positron from 'positron';
import { randomUUID } from 'crypto';
import { AuthProvider } from './authProvider';
import { PositOAuthProvider } from './positOAuthProvider';
import { log } from './log';
import { FOUNDRY_MANAGED_CREDENTIALS, hasManagedCredentials } from './managedCredentials';

Expand Down Expand Up @@ -156,23 +157,32 @@ export async function showConfigurationDialog(
await applyConfig();
}
break;
case 'oauth-signin':
case 'oauth-signin': {
if (hasAuthProvider) {
addResult({ action, config });
const accountId = await handleSave(config);
addResult({ action: 'save', config, accountId });
} else {
await applyConfig();
}
break;
case 'oauth-signout':
}
case 'oauth-signout': {
if (hasAuthProvider) {
addResult({ action, config });
await handleDelete(config);
addResult({ action: 'delete', config });
} else {
await applyConfig();
}
break;
case 'cancel':
}
case 'cancel': {
const provider = authProviders.get(config.provider);
if (provider instanceof PositOAuthProvider) {
provider.cancelSignIn();
}
await applyConfig();
break;
}
default:
throw new Error(
vscode.l10n.t('Invalid action: {0}', action)
Expand Down
2 changes: 2 additions & 0 deletions extensions/authentication/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export const ANTHROPIC_MODELS_ENDPOINT = 'https://api.anthropic.com/v1/models';
export const ANTHROPIC_API_VERSION = '2023-06-01';
export const KEY_VALIDATION_TIMEOUT_MS = 5000;
export const CREDENTIAL_REFRESH_INTERVAL_MS = 10 * 60 * 1000;

export const POSIT_AUTH_PROVIDER_ID = 'posit-ai';
16 changes: 15 additions & 1 deletion extensions/authentication/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import * as vscode from 'vscode';
import * as positron from 'positron';
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
import { POSIT_AUTH_PROVIDER_ID, CREDENTIAL_REFRESH_INTERVAL_MS } from './constants';
import { AuthProvider } from './authProvider';
import { registerAuthProvider, showConfigurationDialog } from './configDialog';
import { normalizeToV1Url, validateAnthropicApiKey, validateFoundryApiKey } from './validation';
import { FOUNDRY_MANAGED_CREDENTIALS, hasManagedCredentials } from './managedCredentials';
import { CREDENTIAL_REFRESH_INTERVAL_MS } from './constants';
import { PositOAuthProvider } from './positOAuthProvider';
import { log } from './log';
import { migrateAwsSettings } from './migration/aws';
import { registerMigrateApiKeyCommand } from './migration/apiKey';
Expand All @@ -19,6 +20,7 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(log);

registerAnthropicProvider(context);
registerPositAIProvider(context);
registerFoundryProvider(context);

// Migrate settings before registering the AWS provider so it
Expand Down Expand Up @@ -60,6 +62,18 @@ function registerAnthropicProvider(context: vscode.ExtensionContext): void {
log.info('Registered auth provider: anthropic-api');
}

function registerPositAIProvider(context: vscode.ExtensionContext): void {
const provider = new PositOAuthProvider(context);
context.subscriptions.push(
vscode.authentication.registerAuthenticationProvider(
POSIT_AUTH_PROVIDER_ID, 'Posit AI', provider
),
provider
);
registerAuthProvider(POSIT_AUTH_PROVIDER_ID, provider);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Here the provider ID is a constant, but above (e.g. 'anthropic-api') IDs are just used inline.

I know this has just come from the older code, and it does not matter for behaviour, but we should probably try to be consistent either way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I migrated all the providers to extension specific constants. I plan to merge this once the PR checks pass!

log.info(`Registered auth provider: ${POSIT_AUTH_PROVIDER_ID}`);
}

function registerAwsProvider(
context: vscode.ExtensionContext
): void {
Expand Down
Loading
Loading