简体   繁体   中英

Ruby on rails devise for authenticity token

I have used Devise gem for authentication, Everything is working fine. But now i want to call one of the controller action from postman service. Am getting problem for login from postman to our application. How can i resolve this.

You can use Simple token authentication gem which works with devise, provides the ability to manage an authentication_token from your model instances. A model with that ability enabled is said to be token authenticatable

In the initializers for simple token authentication you can configure the Headers for which the devise should look for authentication parameters.

Add acts_as_token_authenticatable to your model like User in this case.

Add authentication token attribute to the model(User)

rails g migration add_authentication_token_to_users "authentication_token:string{30}:uniq"
rake db:migrate

In the application controller add the following

acts_as_token_authentication_handler_for User

In simple_token_authentication initializer , you can configure the settings

config.header_names = { user: { authentication_token: 'X-User-Token', email: 'X-User-Email' } }

are defaults.

您可以使用 Postman 同步来同步浏览器和邮递员上的数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM