Skip to content

Instantly share code, notes, and snippets.

@davidbanham
Last active December 1, 2016 14:34
Show Gist options
  • Save davidbanham/9498255 to your computer and use it in GitHub Desktop.
Save davidbanham/9498255 to your computer and use it in GitHub Desktop.
Angular XSRF rack middleware
class TokenAdder
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
response = Rack::Response.new body, status, headers
response.set_cookie(:'XSRF-TOKEN', value: (env["rack.session"][:csrf] ||= SecureRandom.hex(32)), expires: Time.now + 3600*24)
response.finish
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment