@@ -37,12 +37,7 @@ import { getLogger } from '../shared/logger/logger'
3737import { ToolkitError } from '../shared/errors'
3838import { useDeviceFlow } from './sso/ssoAccessTokenProvider'
3939
40- export const AuthStates = {
41- NOT_CONNECTED : 'notConnected' ,
42- CONNECTED : 'connected' ,
43- EXPIRED : 'expired' ,
44- } as const
45- export type AuthState = ( typeof AuthStates ) [ keyof typeof AuthStates ]
40+ export type AuthState = 'notConnected' | 'connected' | 'expired'
4641
4742export type AuthStateEvent = { id : string ; state : AuthState | 'refreshed' }
4843
@@ -161,7 +156,7 @@ export class SsoLogin implements BaseLogin {
161156
162157 // Cached information from the identity server for easy reference
163158 private ssoTokenId : string | undefined
164- private connectionState : AuthState = AuthStates . NOT_CONNECTED
159+ private connectionState : AuthState = 'connected'
165160 private _data : { startUrl : string ; region : string } | undefined
166161
167162 private cancellationToken : CancellationTokenSource | undefined
@@ -183,7 +178,7 @@ export class SsoLogin implements BaseLogin {
183178 }
184179
185180 async reauthenticate ( ) {
186- if ( this . connectionState === AuthStates . NOT_CONNECTED ) {
181+ if ( this . connectionState === 'notConnected' ) {
187182 throw new ToolkitError ( 'Cannot reauthenticate when not connected.' )
188183 }
189184 return this . _getSsoToken ( true )
@@ -193,7 +188,7 @@ export class SsoLogin implements BaseLogin {
193188 if ( this . ssoTokenId ) {
194189 await this . lspAuth . invalidateSsoToken ( this . ssoTokenId )
195190 }
196- this . updateConnectionState ( AuthStates . NOT_CONNECTED )
191+ this . updateConnectionState ( 'notConnected' )
197192 this . _data = undefined
198193 // TODO: DeleteProfile api in Identity Service (this doesn't exist yet)
199194 }
@@ -236,8 +231,8 @@ export class SsoLogin implements BaseLogin {
236231 }
237232
238233 /**
239- * Returns a decrypted access token and a payload to send to the `updateCredentials` API provided by
240- * the Amazon Q LSP.
234+ * Returns both the decrypted access token and the payload to send to the `updateCredentials` LSP API
235+ * with encrypted token
241236 */
242237 async getToken ( ) {
243238 const response = await this . _getSsoToken ( false )
@@ -249,7 +244,7 @@ export class SsoLogin implements BaseLogin {
249244 }
250245
251246 /**
252- * Returns the response from `getToken ` LSP API and sets the connection state based on the errors/result
247+ * Returns the response from `getSsoToken ` LSP API and sets the connection state based on the errors/result
253248 * of the call.
254249 */
255250 private async _getSsoToken ( login : boolean ) {
@@ -277,10 +272,10 @@ export class SsoLogin implements BaseLogin {
277272 case AwsErrorCodes . E_SSO_SESSION_NOT_FOUND :
278273 case AwsErrorCodes . E_PROFILE_NOT_FOUND :
279274 case AwsErrorCodes . E_INVALID_SSO_TOKEN :
280- this . updateConnectionState ( AuthStates . NOT_CONNECTED )
275+ this . updateConnectionState ( 'notConnected' )
281276 break
282277 case AwsErrorCodes . E_CANNOT_REFRESH_SSO_TOKEN :
283- this . updateConnectionState ( AuthStates . EXPIRED )
278+ this . updateConnectionState ( 'expired' )
284279 break
285280 // TODO: implement when identity server emits E_NETWORK_ERROR, E_FILESYSTEM_ERROR
286281 // case AwsErrorCodes.E_NETWORK_ERROR:
@@ -298,7 +293,7 @@ export class SsoLogin implements BaseLogin {
298293 }
299294
300295 this . ssoTokenId = response . ssoToken . id
301- this . updateConnectionState ( AuthStates . CONNECTED )
296+ this . updateConnectionState ( 'connected' )
302297 return response
303298 }
304299
@@ -320,7 +315,7 @@ export class SsoLogin implements BaseLogin {
320315 private ssoTokenChangedHandler ( params : SsoTokenChangedParams ) {
321316 if ( params . ssoTokenId === this . ssoTokenId ) {
322317 if ( params . kind === SsoTokenChangedKind . Expired ) {
323- this . updateConnectionState ( AuthStates . EXPIRED )
318+ this . updateConnectionState ( 'expired' )
324319 return
325320 } else if ( params . kind === SsoTokenChangedKind . Refreshed ) {
326321 this . eventEmitter . fire ( { id : this . profileName , state : 'refreshed' } )
0 commit comments