Skip to content

Commit

Permalink
Remove secret token from repo; use an environment variable instead.
Browse files Browse the repository at this point in the history
Provide instructions for setting the env var in production and non-production environments.
  • Loading branch information
carols10cents committed Sep 4, 2012
1 parent cd47c07 commit 95ad926
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Then update your gemset:

$ gem install bundler && bundle install

Copy the file `config/config.yml.sample` to `config/config.yml` and set a
value for SECRET_TOKEN for both the development and test environments.

And start the server:

$ rails server
Expand Down
9 changes: 9 additions & 0 deletions config/config.yml.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# encoding: utf-8
development:
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# Used in config/initializers/secret_token.rb.
# You can generate a good value for this by running `rake secret`.
SECRET_TOKEN:

# Twitter API stuff (these fake keys work)
CONSUMER_KEY: asdf
CONSUMER_SECRET: asdf
Expand All @@ -18,6 +26,7 @@ development:
domain: localhost.localdomain

test:
SECRET_TOKEN:
CONSUMER_KEY: asdf
CONSUMER_SECRET: asdf
BLOG_URL:
9 changes: 8 additions & 1 deletion config/initializers/secret_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
RstatUs::Application.config.secret_token = 'f9325a55f7a4306eee2f4faa38c8ec1650af793c71ef956d0ba02373f24ac08bd80a4c4f24e5520450e83101ea97c4d732256354fd8c2e34a38067575d800868'
if ENV["SECRET_TOKEN"].blank?
if Rails.env.production?
raise "You must set ENV[\"SECRET_TOKEN\"] in your app's config vars"
else
raise "You must set SECRET_TOKEN in your config.yml"
end
end
RstatUs::Application.config.secret_token = ENV["SECRET_TOKEN"]

0 comments on commit 95ad926

Please sign in to comment.