heroku / heroku-accounts

Helps use multiple accounts on Heroku.
ISC License
549 stars 38 forks source link

Getting "unauthorized" error whenever I switch accounts #20

Closed adamlogic closed 5 years ago

adamlogic commented 5 years ago

I just started seeing this about a month ago. Every time I switch accounts, I see the "Invalid credentials provided" error, and I have to log back in.

❯ heroku accounts:set personal                                                                                   

❯ heroku login --interactive
heroku: Enter your login credentials
Email [adam@adamlogic.com]: 
Password: *********
Two-factor code: ******
Logged in as adam@adamlogic.com

❯ heroku auth:whoami
adam@adamlogic.com

❯ heroku accounts:set obm

❯ heroku auth:whoami     
 ›   Error: Invalid credentials provided.
 ›
 ›   Error ID: unauthorized

❯ heroku login --interactive
heroku: Enter your login credentials
Email [amccrea@orangebarrelmedia.com]: 
Password: *********
Logged in as amccrea@orangebarrelmedia.com

❯ heroku auth:whoami
amccrea@orangebarrelmedia.com

❯ heroku accounts:set personal             

❯ heroku auth:whoami
 ›   Error: Invalid credentials provided.
 ›
 ›   Error ID: unauthorized

Note that I'm using the --interactive flag in this example, but the same thing happens when I auth through the browser.

❯ heroku --version
heroku/7.22.7 darwin-x64 node-v11.10.1
elbandito commented 5 years ago

@adamlogic what version of the accounts plugin are you using?

Run heroku plugins

adamlogic commented 5 years ago
❯ heroku plugins
addons-admin 2.2.1
autocomplete 7.22.7
heroku-accounts 1.1.7
heroku-pg-extras 1.2.1
elbandito commented 5 years ago

@adamlogic I suspect that maybe something is out of sync.

One thing to be aware of is that every time you run heroku login, it will invalidate the last login session for that user and update the ~/.netrc file with a new set of credentials. And while this is happening, your profiles still remain the same and can become stale.

For example, if you run accounts:set personal the CLI plug will copy over your credentials for personal into the ~/.netrc file. Then if you run heroku login -i, the .netrc file will be overridden with a new set of credentials, causing your original credentials that are stored for your personal profile to become obsolete.

As a next step, I recommend you remove the accounts accounts:remove then re-add them accounts:add and make sure you don't run heroku login -i for any of the usernames that are being managed by the accounts CLI plugin.

Try this out and lemme know if you run into the same issue.

adamlogic commented 5 years ago

Yes! That did the trick. Thank you!!!

ykessler commented 5 years ago

As a next step, I recommend you remove the accounts accounts:remove then re-add them accounts:add and make sure you don't run heroku login -i for any of the usernames that are being managed by the accounts CLI plugin.

I'm having same issue. However, I can't remove both accounts like @elbandito suggested because it gives me an "x is the current account" error when I try to remove the current account. Nor does deleting and re-installing the plugin work, as it retains the profiles of the accounts somewhere. Any ideas?

(heroku-accounts version = 1.1.7)

SmartManoj commented 5 years ago

@ykessler remove 1 then add 1 and set as default ; do for other

ykessler commented 5 years ago

@SmartManoj yea thought I already tried that, but it's working now. Not sure what happened.