Exposing Rails/Devise Authentication to iOS application

橙三吉。 提交于 2019-12-03 03:13:24

问题


I have a rails 3.1 application that uses Devise for Authentication with a simple User model with email,password etc. I need to be able to authenticate from an iphone application. How do I expose this functionality? Broad answers are fine as I am not sure what my options are.


回答1:


The fastest way would be to simply enable http_authenticatable and pass the username and password through HTTP Basic Auth. While that's the easiest way, it means you have to store the users password in plaintext and send it along with every request you make.

A better option is token authentication, you can pass it through parameters or HTTP Basic Auth (in which case you can set the password to "X" and the token to the username). The advantage to this is that you can just use the username/password initially to get the token and then use that for any further authentication.

The simplest way to do token authentication with the minimum amount of code would be to enable HTTP authentication in Devise and setup a new controller that requires the user is logged in and all it does is output the result of reset_authentication_token. Once you have the token you would then pass that to any future HTTP authentication requests to log them in.



来源:https://stackoverflow.com/questions/8836238/exposing-rails-devise-authentication-to-ios-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!