Devise API认证 [英] Devise API authentication

查看:88
本文介绍了Devise API认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种还为移动设备提供基于JSON的API的rails Web应用程序。预计移动客户端将首先通过(电子邮件/传递)获取令牌,然后客户端将使用令牌进行后续API调用。

I am working on a rails web application that also provides JSON based API for mobile devices . mobile clients are expected to first obtain a token with (email/pass), then clients will make subsequential API calls with the token.

我是Devise的新手,我正在寻找一个Devise API,看起来像认证(电子邮件,传递),并期望它返回true / false,然后根据我将创建并递回令牌或返回拒绝消息,但似乎Devise不提供这样的东西。

I am pretty new to Devise, and I am looking for a Devise API look like "authenticate(email, pass) and expect it to return true/false, then based on that I will either create and hand back the token or return a decline message. but seems Devise doesn't provide something like this.

我知道Devise 1.3提供基于JSON的认证,但这与我需要的有点不同 - 我需要生成令牌并处理客户端,然后再使用该令牌进行验证。

I am aware that Devise 1.3 provides JSON based auth, but that's a bit different from what I need - I need to generate token and handle back to client, then after that auth is done using the token instead.

有人可以给一些指针吗?

Can someone please give some pointers?

推荐答案

有一个名为的设计配置:token_authenticatable ,所以如果你添加到用户中的设计方法,那么你可以通过调用

There is a devise configuration called :token_authenticatable. So if you add that to the devise method in your "user", then you can authenticate in your API just by calling

"/api/v1/recipes?qs=sweet&auth_token=[@user.auth_token]"

您可能希望在用户以及

before_save :ensure_authentication_token

更新(使用API​​授权码)

UPDATE (with API authorization code)

您要查找的方法是: p>

The method you're looking for are:

resource = User.find_for_database_authentication(:login=>params[:user_login][:login])
resource.valid_password?(params[:user_login][:password])

这是我的 gist与完整的JSON / API登录与设计

这篇关于Devise API认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆