Extending Devise SessionsController to authenticate using JSON

后端 未结 7 1312
面向向阳花
面向向阳花 2020-12-04 05:14

I am trying to build a rails API for an iphone app. Devise works fine for logins through the web interface but I need to be able to create and destroy sessions using REST AP

7条回答
  •  渐次进展
    2020-12-04 05:58

    An alternative solution to creating/destroying sessions is to use Devise's token_authenticatable module, and then update the other functions in your API so that they take the token as a mandatory parameter. This is arguably a more ReSTful design, since it retains statelessness (i.e., there's no session state anywhere). Of course, this advice holds for your JSON API, but I wouldn't recommend the same for your HTML UI (long token strings in your browser's URL bar are not a pretty sight).

    See here for an example.

提交回复
热议问题