Skip to content

Instantly share code, notes, and snippets.

@new-village
Created September 6, 2014 06:05
Show Gist options
  • Save new-village/d9e3bf9a193f21b6a0a2 to your computer and use it in GitHub Desktop.
Save new-village/d9e3bf9a193f21b6a0a2 to your computer and use it in GitHub Desktop.
config/initializers/secret_token.rb
# Be sure to restart your server when you modify this file.
# Your secret key is used 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.
# You can use `rake secret` to generate a secure secret key.
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
require 'securerandom'
def secure_token
token_file = Rails.root.join('.secret')
if File.exist?(token_file)
# Use the existing token.
File.read(token_file).chomp
else
# Generate a new token and store it in token_file.
token = SecureRandom.hex(64)
File.write(token_file, token)
token
end
end
Xapp7::Application.config.secret_key_base = secure_token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment