如何在 heroku dyno 中获得经过身份验证的用户?

How to get the authenticated users in a heroku dyno?

有谁知道如何在 heroku dyno 中获取已登录用户的凭据?

上下文:我们正在尝试记录对 Heroku 产品的访问 rails console。人们通过 heroku runheroku exec 访问它。 Heroku 确实对执行命令的用户进行了身份验证,但是,一旦 rails 控制台启动,我就无法检索此信息。

看起来 heroku cli 在 dyno 中不可用,并且 whoami returns dyno.

例如:

$ heroku run rails c -a opt-prod

<in rails console> 

irb(main):001:0> ENV
irb(main):001:0> `whoami`

我们联系了 Heroku,没有办法做到这一点。相反,

A running dyno doesn't contain information on the user that started the process, so there's no way to get the "current user" from inside a dyno on Heroku.

However, one idea for a workaround is to grab the current Heroku CLI user and sends it along with the console command when starting. Something like this will work:

CURRENT_HEROKU_USER="$CURRENT_HEROKU_USER" rails c --app my-app-name

> Running CURRENT_HEROKU_USER=chap@heroku.com rails c...

ENV['CURRENT_HEROKU_USER']

> "chap@heroku.com" 

The downside of this approach is there's no way to validate that value from inside the dyno. However you could use your application logs to retroactively verify the info. The API will log the user who started the console process in your application logs:

CURRENT_HEROKU_USER=chap@heroku.com rails c by user chap@heroku.com

I'm sorry we don't have a better answer for you here.

Please let me know if I can be of more help.