Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store keys for API's in Rails?

I have several api's that I am integrating with and need to call in various parts of my application.

What is the way to store the keys, the user/password, or token information, say, a configuration file and then how do I call them for use in other parts of the application?

Thanks.

like image 991
Satchel Avatar asked Jul 21 '10 02:07

Satchel


People also ask

Where should I store my API keys?

Instead of embedding your API keys in your applications, store them in environment variables or in files outside of your application's source tree.

Should API keys be stored hashed?

Storage: API keys should not be stored as plain text but rather stored as a hashed value in the database to prevent copying. Even if an attacker successfully targets the key management database, the keys are unusable.


1 Answers

Just to keep this question up-to-date, there is a new way to do this in Rails 4.1:

From the Rails guides:

Rails 4.1 generates a new secrets.yml file in the config folder. By default, this file contains the application's secret_key_base, but it could also be used to store other secrets such as access keys for external APIs.

like image 184
benjaminjosephw Avatar answered Nov 08 '22 14:11

benjaminjosephw