StaticTokenAuthService.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import EventEmitter from "events"
  2. import * as vscode from "vscode"
  3. import type { CloudUserInfo } from "@roo-code/types"
  4. import type { AuthService, AuthServiceEvents, AuthState } from "./AuthService"
  5. export class StaticTokenAuthService extends EventEmitter<AuthServiceEvents> implements AuthService {
  6. private state: AuthState = "active-session"
  7. private token: string
  8. private log: (...args: unknown[]) => void
  9. constructor(context: vscode.ExtensionContext, token: string, log?: (...args: unknown[]) => void) {
  10. super()
  11. this.token = token
  12. this.log = log || console.log
  13. this.log("[auth] Using static token authentication mode")
  14. }
  15. public async initialize(): Promise<void> {
  16. const previousState: AuthState = "initializing"
  17. this.state = "active-session"
  18. this.emit("auth-state-changed", { state: this.state, previousState })
  19. this.log("[auth] Static token auth service initialized in active-session state")
  20. }
  21. public async login(): Promise<void> {
  22. throw new Error("Authentication methods are disabled in StaticTokenAuthService")
  23. }
  24. public async logout(): Promise<void> {
  25. throw new Error("Authentication methods are disabled in StaticTokenAuthService")
  26. }
  27. public async handleCallback(
  28. _code: string | null,
  29. _state: string | null,
  30. _organizationId?: string | null,
  31. ): Promise<void> {
  32. throw new Error("Authentication methods are disabled in StaticTokenAuthService")
  33. }
  34. public getState(): AuthState {
  35. return this.state
  36. }
  37. public getSessionToken(): string | undefined {
  38. return this.token
  39. }
  40. public isAuthenticated(): boolean {
  41. return true
  42. }
  43. public hasActiveSession(): boolean {
  44. return true
  45. }
  46. public hasOrIsAcquiringActiveSession(): boolean {
  47. return true
  48. }
  49. public getUserInfo(): CloudUserInfo | null {
  50. return {}
  51. }
  52. public getStoredOrganizationId(): string | null {
  53. return null
  54. }
  55. }