Heroku Login Multi-Factor Authentication mfa_required error (without opening a browser)

Viewed 493

When using Heroku Multi-Factor Authentication, is there any way to login via the console without opening the browser?

ubuntu:~/environment $ heroku login -i
heroku: Enter your login credentials
Email [hello@gmail.com]: 
Password: ****************
 ›   Error: Your account has MFA enabled; API requests using basic authentication with email and password are not supported. Please 
 ›   generate an authorization token for API access. 
 ›
 ›   Error ID: mfa_required
3 Answers

Yes. Basically, to set this up what you want to do is:

  1. Login to Heroku and create an API Token under "Account settings". (You said "without opening a browser", and I'm assuming you mean 'How to authenticate from the command-line'. To set this up you will need to open a browser ... once ;)
  2. In your local machine's home directory, check to see if you already have a file called .netrc. If not, simply create one like so -- touch ~/.netrc.
  3. From there you'll want to append the following to that file (and save):
machine api.heroku.com
 login <your-email-goes-here>
 password <the-api-token-goes-here>
machine git.heroku.com
 login <your-email-goes-here>
 password <the-api-token-goes-here>
  1. If you just created the .netrc file you'll want to chmod 600 .netrc to give it necessary permissions.
  2. At this point, you can try the command heroku auth:whoami and hopefully see your user e-mail printed back to you.

FWIW, Heroku does have some docs covering this here, but to be honest, the docs are rather disjointed and I would think unhelpful to someone that's never done something like this before, which is why I tried to go step-by-step.

I hope this is what you wanted and / or someone finds this helpful :)

For multi-factor authentication enabled heroku account, If you can get the API key then there is a simpler way to sign in via CLI. type -> heroku login -i

enter the email id associated with your heroku account and for password you must enter the API key that you got from the account settings page.

If you are willing to turn off the MFA

This is the solution: Go to https://dashboard.heroku.com/account and scroll down in the account settings to find Multi factor Authentication enabled.

Click on the same and then disable the MFA , you are good to go !

Related