Skip to content

Commit

Permalink
Auth: supports codium and cursor for enterprise instances (#3257)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeatrix authored Feb 24, 2024
1 parent 6ffc743 commit 3b30f7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
7 changes: 2 additions & 5 deletions vscode/src/services/AuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import { localStorage } from './LocalStorageProvider'
import { secretStorage } from './SecretStorageProvider'
import { telemetryService } from './telemetry'
import { telemetryRecorder } from './telemetry-v2'
import { getAuthReferralCode } from './AuthProviderSimplified'

type Listener = (authStatus: AuthStatus) => void
type Unsubscribe = () => void

export class AuthProvider {
private endpointHistory: string[] = []

private appScheme = vscode.env.uriScheme
private client: SourcegraphGraphQLAPIClient | null = null

private authStatus: AuthStatus = defaultAuthStatus
Expand Down Expand Up @@ -396,10 +396,7 @@ export class AuthProvider {
}

const newTokenCallbackUrl = new URL('/user/settings/tokens/new/callback', endpoint)
newTokenCallbackUrl.searchParams.append(
'requestFrom',
this.appScheme === 'vscode-insiders' ? 'CODY_INSIDERS' : 'CODY'
)
newTokenCallbackUrl.searchParams.append('requestFrom', getAuthReferralCode())
this.authStatus.endpoint = endpoint
void vscode.env.openExternal(vscode.Uri.parse(newTokenCallbackUrl.href))
}
Expand Down
21 changes: 14 additions & 7 deletions vscode/src/services/AuthProviderSimplified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,26 @@ export class AuthProviderSimplified {
}
}

/**
* Returns a known referral code to use based on the current VS Code environment.
*/
export function getAuthReferralCode(): string {
return (
{
'vscode-insiders': 'CODY_INSIDERS',
vscodium: 'CODY_VSCODIUM',
cursor: 'CODY_CURSOR',
}[vscode.env.uriScheme] || 'CODY'
)
}

// Opens authentication URLs for simplified onboarding.
async function openExternalAuthUrl(provider: AuthMethod): Promise<boolean> {
// Create the chain of redirects:
// 1. Specific login page (GitHub, etc.) redirects to the post-sign up survey
// 2. Post-sign up survery redirects to the new token page
// 3. New token page redirects back to the extension with the new token
const uriScheme = vscode.env.uriScheme
const referralCode =
{
'vscode-insiders': 'CODY_INSIDERS',
vscodium: 'CODY_VSCODIUM',
cursor: 'CODY_CURSOR',
}[uriScheme] || 'CODY'
const referralCode = getAuthReferralCode()
const newTokenUrl = `/user/settings/tokens/new/callback?requestFrom=${referralCode}`
const postSignUpSurveyUrl = `/post-sign-up?returnTo=${newTokenUrl}`
const site = DOTCOM_URL.toString() // Note, ends with the path /
Expand Down

0 comments on commit 3b30f7d

Please sign in to comment.