malcoauri
malcoauri

Reputation: 12189

How to generate csrf token for API?

I'm developing some API for my mobile app, and I want to add some action to render CSRF token in JSON. I know that there is helper csrf_meta_tags for HTML views, but how can I do it in controller? Thanks in advance.

Upvotes: 4

Views: 6675

Answers (2)

Baldrick
Baldrick

Reputation: 24340

You can use form_authenticity_token in the controller. It uses session[:_csrf_token] as suggested by @user123, and also initialize it if it has not been done yet (see source).

Upvotes: 3

junil
junil

Reputation: 768

use the value in

session[:_csrf_token]

Upvotes: 2

Related Questions