Rails how to store passwords for other services?

妖精的绣舞 提交于 2019-12-23 03:37:06

问题


What is the safest way of storing passwords that is used to other services?

Example:

App that needs to store passwords for other sites to do a rake task for fetching data that require authentication.


回答1:


You would store this data as environment variables. For example, for one of my projects I need my app to have access to a Github login. This Github login is stored as an environment variable by adding the following line to my .bashrc file.

export GITHUB_LOGIN=myLogin

In my app's config file I refer to this environment variable like this:

:github_login: <%= ENV['GITHUB_LOGIN'] %>

This config file is then loaded by the app like this:

require 'erb'
raw_data = File.read(config_file)
erbified_data = ERB.new(raw_data).result


来源:https://stackoverflow.com/questions/15978253/rails-how-to-store-passwords-for-other-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!