我有rails应用程序,它也可以作为api使用devise身份验证,就rails应用程序而言,身份验证进行得很好。但是在Rails Api的情况下,为什么我需要像传递auth_token一样传递auth_token.Looks需要定制设备控制器,它似乎是使用rest客户端的请求体中的pain.Passing auth_token允许我通过Post方法登录,但我没有找到任何响应。我需要定制devise控制器吗?
我需要帮助谢谢,
发布于 2013-02-12 23:08:02
我不想将您的:auth_token
附加到客户端的POST/PUT
参数中,而是将此令牌作为请求标头发送。
你可以这样做-
class YourController < ApplicationController
prepend_before_filter :get_api_key
before_filter :authenticate_user!
private
def get_api_key
if api_key = params[:api_key].blank? && request.headers["X-API-KEY"]
params[:api_key] = api_key
end
end
end
然后说你的用于devise的认证密钥设置我们的api密钥,比如-
config.token_authentication_key = :api_key
您还可以使用自定义策略来支持this等设备中的token HTTP header身份验证
https://stackoverflow.com/questions/14835053
复制相似问题