Skip to content

Commit

Permalink
Revert "feat(auth): Allow workspace to pre-populate URL for quick sig…
Browse files Browse the repository at this point in the history
…n-in (#6653)" (#6794)

## Description

This reverts commit
9719dc4.

## Test plan

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

This revert will be part of a series of reverts, we will validate that
the intended behaviour is restored.

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
  • Loading branch information
umpox authored Jan 27, 2025
1 parent 95b0e79 commit 3027b3e
Show file tree
Hide file tree
Showing 53 changed files with 176 additions and 802 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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)
else -> throw Exception("Unknown discriminator ${element}")
}
}
Expand Down Expand Up @@ -51,14 +50,3 @@ data class EnterpriseUserDotComError(
}
}

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

enum class TypeEnum {
@SerializedName("auth-config-error") `Auth-config-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 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
2 changes: 1 addition & 1 deletion agent/src/cli/scip-codegen/emitters/KotlinEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class KotlinFormatter extends Formatter {
}

override formatFieldName(name: string): string {
const escaped = name.replace('.*', 'Wildcard').replace(':', '_').replace('/', '_')
const escaped = name.replace(':', '_').replace('/', '_')
const isKeyword = this.options.reserved.has(escaped)
const needsBacktick = isKeyword || !/^[a-zA-Z0-9_]+$/.test(escaped)
// Replace all non-alphanumeric characters with underscores
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
12 changes: 1 addition & 11 deletions lib/shared/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ export interface EnterpriseUserDotComError {
enterprise: string
}

export interface AuthConfigError extends AuthenticationErrorMessage {
type: 'auth-config-error'
}

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

export interface AuthenticationErrorMessage {
title?: string
Expand Down Expand Up @@ -98,8 +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 error
}
}

Expand Down
30 changes: 2 additions & 28 deletions lib/shared/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +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(): Record<string, string>
expiration: number | undefined
}

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

export interface AutoEditsTokenLimit {
Expand Down Expand Up @@ -82,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 @@ -189,8 +165,6 @@ interface RawClientConfiguration {
*/
overrideServerEndpoint?: string | undefined
overrideAuthToken?: string | undefined

authExternalProviders: ExternalAuthProvider[]
}

/**
Expand Down
Loading

0 comments on commit 3027b3e

Please sign in to comment.