Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 9e9bd44

Browse files
committed
Add SMS support
1 parent c76da5e commit 9e9bd44

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"types": "dist/index.d.ts",
1010
"bin": {
11-
"extaws": "dist/lib/extaws.js"
11+
"extaws": "dist/lib/extaws-cli.js"
1212
},
1313
"repository": "[email protected]:helloextend/extaws.git",
1414
"author": "Corey Ryan <[email protected]>",

src/lib/extaws.ts

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,53 @@ export class ExtAws {
108108
}))
109109
spinner?.start('Logging in...')
110110
}
111-
do {
112-
verify = await this.verifyFactor({ id: factor, stateToken: authResponse.stateToken}, totpPrompt)
113-
if (!('status' in verify)) {
114-
throw new Error(verify.message)
111+
if ( type === 'sms') {
112+
do {
113+
verify = await this.verifyFactor({ id: factor, stateToken: authResponse.stateToken}, totpPrompt)
114+
115+
spinner?.stop()
116+
;({ totpPrompt } = await ExtAws.inquire({
117+
name: 'totpPrompt',
118+
type: 'input',
119+
message: 'SMS Code:',
120+
}))
121+
spinner?.start('Logging in...')
122+
123+
verify = await this.verifyFactor({ id: factor, stateToken: authResponse.stateToken}, totpPrompt)
124+
if (!('status' in verify)) {
125+
spinner?.stop()
126+
throw new Error(verify.message)
127+
}
128+
129+
} while(verify.status !== 'SUCCESS' && verify.stateToken)
130+
131+
if (!verify.sessionToken) {
132+
throw new Error('No session token in response')
115133
}
116-
if (verify.status !== 'SUCCESS') await sleep(1000)
117-
if (counter > 30) {
118-
console.log('Timing out after thirty seconds')
119-
console.log(`Auth State: ${verify.status}`)
120-
process.exit(1)
121-
}
122-
counter++
123-
} while(verify.status !== 'SUCCESS' && verify.stateToken)
134+
this.sessionToken = verify.sessionToken
124135

125-
if (!verify.sessionToken) {
126-
throw new Error('No session token in response')
136+
} else {
137+
do {
138+
verify = await this.verifyFactor({ id: factor, stateToken: authResponse.stateToken}, totpPrompt)
139+
if (!('status' in verify)) {
140+
spinner?.stop()
141+
throw new Error(verify.message)
142+
}
143+
if (verify.status !== 'SUCCESS') await sleep(1000 * counter * counter)
144+
if (counter > 30) {
145+
console.log('Timing out after thirty seconds')
146+
console.log(`Auth State: ${verify.status}`)
147+
process.exit(1)
148+
}
149+
counter++
150+
} while(verify.status !== 'SUCCESS' && verify.stateToken)
151+
152+
if (!verify.sessionToken) {
153+
throw new Error('No session token in response')
154+
}
155+
this.sessionToken = verify.sessionToken
127156
}
128157

129-
this.sessionToken = verify.sessionToken
130-
131158
} else {
132159
throw new Error('Unable to find factors in auth response')
133160
}
@@ -267,6 +294,8 @@ export class ExtAws {
267294
duration = inputDuration
268295
}
269296

297+
if (duration > 43200) duration = 43200
298+
270299
let awsRegion: string
271300
if (!inputAwsRegion) {
272301
const { promptAwsRegion } = await ExtAws.inquire({

src/lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface ExtAwsUserConfig {
3333
}
3434
}
3535

36-
export type FactorDevice = 'token:software:totp' | 'push'
36+
export type FactorDevice = 'token:software:totp' | 'push' | 'sms'
3737

3838
export type FactorSelect = {
3939
factor: string,

0 commit comments

Comments
 (0)