Company is swtiching from RSA SecurID Token to Microsoft Multi-Factor Authentication, Microsoft provide many ways to support Multi-Factor Authentication ( MFA ), you can install MS Authenticator App on Phone, using Outlook App, SMS messages … but the best is still able to through CLI which make it possible to integrate with other Schell Script files, and no need to pickup your phone.
Previous tools like stoken is not working anymore, we need a new setup for it. check RSA implementation at here.
Step 1: Install TOTP
We need regist our Terminal Tool to Microsoft as the same as a Phone Application, basically we just need a tool for supporting TOTP ( Time-based one-time password ), here choose oathtool.
For MacOS:
➜ brew install oath-toolkit
To generate a time-based OTP (most common for 2FA):
➜ oathtool --base32 --totp <YOUR_SECRET_KEY_IN_BASE32>
For example, If your Base32 secret key is GEZDGNBVGY3TQOJQ, run following command will generate the token:
➜ oathtool --base32 --totp GEZDGNBVGY3TQOJQ
272419
Step 2: Regist Oathtool to Microsoft
- Go to: https://mysignins.microsoft.com/security-info
- Click “Add sign-in method”
- Click “Microsoft Authenticator”
- Click “I want to use a different authenticator app” -> “Next” -> “Can’t scan image?” -> Will display Account name and Secrect key ( store Secrect Key safely for later usage )
- Click “Next” button, will display a dialogue waiting for “Enter the 6-digit code shown in the Authenticator app”
- Use oathtool to generate the 6 digits token mentioned in Step 1, then enter and click Next
- You should now see “Authenticator app was successfully registered” and TOTP will be shown in security-info page:
Step 3: Use Token
Now when login to MS MFA, choose “Use a verification code”, and use the token generated from oathtool in Step 1.
Step 4: Alfred Integration
To use it easier, we can create a Alfred Workflow:
The Script FIlter with following:
ms_stoken=$(echo | oathtool --base32 --totp GEZDGNBVGY3TQOJQ | tr -d '\n')
cat<<EOB
<?xml version="1.0"?>
<items>
<item uid="mstoken" arg="$ms_stoken">
<title>MS Token: $ms_stoken</title>
<subtitle>Press Enter to paste, or Cmd+C to copy</subtitle>
<icon>icon.png</icon>
</item>
</items>
EOB
References
- Just One-click! Connect to Cisco VPN
- Command Line One Time Passwords for Microsoft Multi-Factor Authentication
- What authentication and verification methods are available in Microsoft Entra ID