【发布时间】:2011-08-01 14:32:04
【问题描述】:
我有一个小型应用程序,我将有一些外部应用程序通过 http 将数据发送到此服务并休息。我已经让它工作但没有身份验证。在门户中我使用设计,我的问题是:如何(所需示例)从 ruby 脚本级别对门户进行身份验证?首先要在以下脚本中添加什么来进行身份验证?我想用设计保护这个控制器,然后我需要对以下脚本进行身份验证。
require "net/http"
require "json"
@host = "localhost"
@port = 3000
@post_ws = "/external/rd"
@req_body = {
"device" => {
"name" => "device_json",
"operating_system_id" => "7",
"hash_string" => "jfsg3k4ovj0j02jv",
"user_id" => "1"
}
}.to_json
req = Net::HTTP::Post.new(@post_ws, initheader = {'Content-Type' =>'application/json'})
req.body = @req_body
response = Net::HTTP.new(@host, @port).start {|http| http.request(req) }
问候, 马特乌斯
【问题讨论】:
-
我看到 token_authenticable 可能会有所帮助,但目前还不知道如何从脚本中获取令牌,所以仍然没有解决方案:/
标签: ruby ruby-on-rails-3 authentication rest devise