Skip to content

Commit

Permalink
Fix the MFA Login command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Gawron committed Mar 3, 2022
1 parent c8b9d4a commit b299d85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/Commands/AwsMfaLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function handle()

$envVars = $this->helpers->aws()->iam()->authenticateWithMfaDevice($mfaDevice, $code);

if (empty($envVars)) {
$this->error("Unable to authenicate MFA");
return 1;
}

$this->info("Now opening a session following your MFA authentication. Type `exit` to leave this shell.");

(new Process([config('app.shell')]))
Expand Down
14 changes: 9 additions & 5 deletions app/Helpers/Aws/Iam.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ public function authenticateWithMfaDevice($mfaDeviceArn, $code): array
];

try {
$processOutput = $this->aws->newProcess($commandOptions)
->run();
$processOutput = $this->aws->newProcess($commandOptions)->run();
} catch (ProcessFailed $e) {
$this->command->error("Unable to authenicate MFA");
return null;
return [];
}

return json_decode($processOutput, true);
$result = json_decode($processOutput, true);

return [
'AWS_ACCESS_KEY_ID' => $result['Credentials']['AccessKeyId'],
'AWS_SECRET_ACCESS_KEY' => $result['Credentials']['SecretAccessKey'],
'AWS_SESSION_TOKEN' => $result['Credentials']['SessionToken'],
];
}

public function assumeRole(int $accountId, string $role, string $sessionUser, ?string $mfaDevice = null, ?string $mfaCode = null): array
Expand Down

0 comments on commit b299d85

Please sign in to comment.