Skip to content

Commit

Permalink
[Backport jb-v7.12.x] Revert commits 9719dc4, 1c16f35, 1ed8392, 03c93f9
Browse files Browse the repository at this point in the history
… (#6811)

## Description

See
[#inc-365-jetbrains-and-vscode-auth-errors](https://sourcegraph.slack.com/archives/C089N0XTC0P)

- [Revert "Refactor external auth providers to re-generate headers
on
de…](76f7d78)

- [Revert "feat(auth): Allow workspace to pre-populate URL for
quick
sig…](3b4c48c)

- [Revert "Improve reporting auth
errors"](89d26c5)

- [Revert "External Authentication Providers Support for
Cody"](41e4ec6)

## Test plan

Initial behaviour is restored. See
[#inc-365-jetbrains-and-vscode-auth-errors](https://sourcegraph.slack.com/archives/C089N0XTC0P)




 <br> Backport 3fca0f6 from #6788

---------

Co-authored-by: Tom Ross <tom@umpox.com>
  • Loading branch information
sourcegraph-release-bot and umpox authored Jan 27, 2025
1 parent 7ef37d4 commit f5b9449
Show file tree
Hide file tree
Showing 53 changed files with 200 additions and 966 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ sealed class AuthenticationError {
"network-error" -> context.deserialize<NetworkAuthError>(element, NetworkAuthError::class.java)
"invalid-access-token" -> context.deserialize<InvalidAccessTokenError>(element, InvalidAccessTokenError::class.java)
"enterprise-user-logged-into-dotcom" -> context.deserialize<EnterpriseUserDotComError>(element, EnterpriseUserDotComError::class.java)
"auth-config-error" -> context.deserialize<AuthConfigError>(element, AuthConfigError::class.java)
"external-auth-provider-error" -> context.deserialize<ExternalAuthProviderError>(element, ExternalAuthProviderError::class.java)
else -> throw Exception("Unknown discriminator ${element}")
}
}
Expand Down Expand Up @@ -52,23 +50,3 @@ data class EnterpriseUserDotComError(
}
}

data class AuthConfigError(
val type: TypeEnum, // Oneof: auth-config-error
val message: String,
) : AuthenticationError() {

enum class TypeEnum {
@SerializedName("auth-config-error") `Auth-config-error`,
}
}

data class ExternalAuthProviderError(
val type: TypeEnum, // Oneof: external-auth-provider-error
val message: String,
) : AuthenticationError() {

enum class TypeEnum {
@SerializedName("external-auth-provider-error") `External-auth-provider-error`,
}
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport")
package com.sourcegraph.cody.agent.protocol_generated;

import com.google.gson.annotations.SerializedName;

data class CodyContextFilterItem(
val repoNamePattern: RepoNamePatternEnum, // Oneof: .*
val repoNamePattern: String,
val filePathPatterns: List<String>? = null,
) {

enum class RepoNamePatternEnum {
@SerializedName(".*") Wildcard,
}
}
)

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package com.sourcegraph.cody.agent.protocol_generated;

object Constants {
const val Wildcard = ".*"
const val Applied = "Applied"
const val Applying = "Applying"
const val Automatic = "Automatic"
Expand All @@ -16,7 +15,6 @@ object Constants {
const val agentic = "agentic"
const val ask = "ask"
const val assistant = "assistant"
const val `auth-config-error` = "auth-config-error"
const val authenticated = "authenticated"
const val autocomplete = "autocomplete"
const val balanced = "balanced"
Expand All @@ -41,7 +39,6 @@ object Constants {
const val `enterprise-user-logged-into-dotcom` = "enterprise-user-logged-into-dotcom"
const val error = "error"
const val experimental = "experimental"
const val `external-auth-provider-error` = "external-auth-provider-error"
const val file = "file"
const val free = "free"
const val function = "function"
Expand Down
80 changes: 0 additions & 80 deletions agent/scripts/reverse-proxy.py

This file was deleted.

21 changes: 0 additions & 21 deletions agent/scripts/simple-external-auth-provider.py

This file was deleted.

2 changes: 1 addition & 1 deletion agent/src/AgentWorkspaceConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class AgentWorkspaceConfiguration implements vscode.WorkspaceConfiguratio

function mergeWithBaseConfig(config: any) {
for (const [key, value] of Object.entries(config)) {
if (typeof value === 'object' && !Array.isArray(value)) {
if (typeof value === 'object') {
const existing = _.get(baseConfig, key) ?? {}
const merged = _.merge(existing, value)
_.set(baseConfig, key, merged)
Expand Down
9 changes: 4 additions & 5 deletions agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1486,10 +1486,11 @@ export class Agent extends MessageHandler implements ExtensionClient {
config: ExtensionConfiguration,
params?: { forceAuthentication: boolean }
): Promise<AuthStatus> {
const isAuthChange = vscode_shim.isTokenOrEndpointChange(config)
const isAuthChange = vscode_shim.isAuthenticationChange(config)
vscode_shim.setExtensionConfiguration(config)

// If this is an token or endpoint change we need to save them prior to firing events that update the clients
// If this is an authentication change we need to reauthenticate prior to firing events
// that update the clients
try {
if ((isAuthChange || params?.forceAuthentication) && config.serverEndpoint) {
await authProvider.validateAndStoreCredentials(
Expand All @@ -1499,9 +1500,7 @@ export class Agent extends MessageHandler implements ExtensionClient {
},
auth: {
serverEndpoint: config.serverEndpoint,
credentials: config.accessToken
? { token: config.accessToken, source: 'paste' }
: undefined,
accessToken: config.accessToken ?? null,
},
clientState: {
anonymousUserID: config.anonymousUserID ?? null,
Expand Down
5 changes: 1 addition & 4 deletions agent/src/cli/command-auth/AuthenticatedAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export class AuthenticatedAccount {
): Promise<AuthenticatedAccount | Error> {
const graphqlClient = SourcegraphGraphQLAPIClient.withStaticConfig({
configuration: { telemetryLevel: 'agent' },
auth: {
credentials: { token: options.accessToken },
serverEndpoint: options.endpoint,
},
auth: { accessToken: options.accessToken, serverEndpoint: options.endpoint },
clientState: { anonymousUserID: null },
})
const userInfo = await graphqlClient.getCurrentUserInfo()
Expand Down
4 changes: 2 additions & 2 deletions agent/src/cli/command-auth/command-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async function loginAction(
: await captureAccessTokenViaBrowserRedirect(serverEndpoint, spinner)
const client = SourcegraphGraphQLAPIClient.withStaticConfig({
configuration: { telemetryLevel: 'agent' },
auth: { credentials: { token: options.accessToken }, serverEndpoint: serverEndpoint },
auth: { accessToken: token, serverEndpoint: serverEndpoint },
clientState: { anonymousUserID: null },
})
const userInfo = await client.getCurrentUserInfo()
Expand Down Expand Up @@ -256,7 +256,7 @@ async function promptUserAboutLoginMethod(spinner: Ora, options: LoginOptions):
try {
const client = SourcegraphGraphQLAPIClient.withStaticConfig({
configuration: { telemetryLevel: 'agent' },
auth: { credentials: { token: options.accessToken }, serverEndpoint: options.endpoint },
auth: { accessToken: options.accessToken, serverEndpoint: options.endpoint },
clientState: { anonymousUserID: null },
})
const userInfo = await client.getCurrentUserInfo()
Expand Down
2 changes: 1 addition & 1 deletion agent/src/cli/command-bench/command-bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export const benchCommand = new commander.Command('bench')
setStaticResolvedConfigurationWithAuthCredentials({
configuration: { customHeaders: {} },
auth: {
credentials: { token: options.srcAccessToken },
accessToken: options.srcAccessToken,
serverEndpoint: options.srcEndpoint,
},
})
Expand Down
5 changes: 1 addition & 4 deletions agent/src/cli/command-bench/llm-judge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export class LlmJudge {
localStorage.setStorage('noop')
setStaticResolvedConfigurationWithAuthCredentials({
configuration: { customHeaders: undefined },
auth: {
credentials: { token: options.srcAccessToken },
serverEndpoint: options.srcEndpoint,
},
auth: { accessToken: options.srcAccessToken, serverEndpoint: options.srcEndpoint },
})
setClientCapabilities({ configuration: {}, agentCapabilities: undefined })
this.client = new SourcegraphNodeCompletionsClient()
Expand Down
5 changes: 1 addition & 4 deletions agent/src/local-e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ export class LocalSGInstance {
// for checking the LLM configuration section.
this.gqlclient = SourcegraphGraphQLAPIClient.withStaticConfig({
configuration: { customHeaders: headers, telemetryLevel: 'agent' },
auth: {
credentials: { token: this.params.accessToken },
serverEndpoint: this.params.serverEndpoint,
},
auth: { accessToken: this.params.accessToken, serverEndpoint: this.params.serverEndpoint },
clientState: { anonymousUserID: null },
})
}
Expand Down
3 changes: 1 addition & 2 deletions agent/src/vscode-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ export let extensionConfiguration: ExtensionConfiguration | undefined
export function setExtensionConfiguration(newConfig: ExtensionConfiguration): void {
extensionConfiguration = newConfig
}

export function isTokenOrEndpointChange(newConfig: ExtensionConfiguration): boolean {
export function isAuthenticationChange(newConfig: ExtensionConfiguration): boolean {
if (!extensionConfiguration) {
return true
}
Expand Down
27 changes: 1 addition & 26 deletions lib/shared/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,7 @@ export interface EnterpriseUserDotComError {
enterprise: string
}

export interface AuthConfigError {
type: 'auth-config-error'
message: string
}

export interface ExternalAuthProviderError {
type: 'external-auth-provider-error'
message: string
}

export type AuthenticationError =
| NetworkAuthError
| InvalidAccessTokenError
| EnterpriseUserDotComError
| AuthConfigError
| ExternalAuthProviderError
export type AuthenticationError = NetworkAuthError | InvalidAccessTokenError | EnterpriseUserDotComError

export interface AuthenticationErrorMessage {
title?: string
Expand Down Expand Up @@ -105,16 +90,6 @@ export function getAuthErrorMessage(error: AuthenticationError): AuthenticationE
"in through your organization's enterprise instance instead. If you need assistance " +
'please contact your Sourcegraph admin.',
}
case 'auth-config-error':
return {
title: 'Auth Config Error',
message: error.message,
}
case 'external-auth-provider-error':
return {
title: 'External Auth Provider Error',
message: error.message,
}
}
}

Expand Down
29 changes: 2 additions & 27 deletions lib/shared/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ export type TokenSource = 'redirect' | 'paste'
*/
export interface AuthCredentials {
serverEndpoint: string
credentials: HeaderCredential | TokenCredential | undefined
error?: any
}

export interface HeaderCredential {
// We use function instead of property to prevent accidential top level serialization - we never want to store this data
getHeaders(): Promise<Record<string, string>>
}

export interface TokenCredential {
token: string
source?: TokenSource
accessToken: string | null
tokenSource?: TokenSource | undefined
}

export interface AutoEditsTokenLimit {
Expand Down Expand Up @@ -81,19 +71,6 @@ export interface AgenticContextConfiguration {
}
}

export interface ExternalAuthCommand {
commandLine: readonly string[]
environment?: Record<string, string>
shell?: string
timeout?: number
windowsHide?: boolean
}

export interface ExternalAuthProvider {
endpoint: string
executable: ExternalAuthCommand
}

interface RawClientConfiguration {
net: NetConfiguration
codebase?: string
Expand Down Expand Up @@ -188,8 +165,6 @@ interface RawClientConfiguration {
*/
overrideServerEndpoint?: string | undefined
overrideAuthToken?: string | undefined

authExternalProviders: ExternalAuthProvider[]
}

/**
Expand Down
Loading

0 comments on commit f5b9449

Please sign in to comment.