- 我们有一个 iPad 应用程序,显示来自 drupal 站点的内容(仅提供 json 文件)。
- 我们的 IT 部门在 drupal 站点前面放置了一个 SSO。 WebSEAL 用于实现 SSO。
- 因此,当我们从浏览器访问 drupal 站点时,我们会被重定向到登录页面(表单例份验证),并且需要输入 Windows 用户名和密码才能继续。
当我们尝试从 ipad 访问 json 文件时,我们收到 401 状态,其中包含 html 内容和登录页面的 url。我们尝试通过在 header 中发送用户名和密码来使用基本身份验证,但它不起作用。谷歌搜索没有给出任何有用的解决方案。
有人遇到过类似的问题吗?我只需要一种从非浏览器客户端使用用户名和密码进行身份验证的方法。
示例节点 js 代码
var http = require('http');
var username = 'username';
var password = 'password';
var auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
var options = {
host: 'devhome.intranet.example.com',
port: 80,
path: '/app/api/rest/views/category.json',
headers : {
"Authorization" : auth
}
};
http.get(options, function(res) {
console.log("Got response: " + res.statusCode);
console.log(res);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
非常感谢任何帮助。
谢谢
最佳答案
我知道这是一个老问题,但我尝试做非常类似的事情(.Net 客户端访问 WebSeal 后面的 Web 服务)。谷歌搜索后没有有用的解决方案。
但是 IBM 文档给了我一个线索 http://www.ibm.com/support/knowledgecenter/SSPREK_8.0.1.2/com.ibm.isamw.doc_8.0.1.2/wrp_config/task/tsk_submt_form_data_ws.html
基本上,当您从浏览器通过 Webseal 访问资源时,Webseal 会使用登录页面进行响应。输入用户名和密码后,表单数据将提交到/pkmslogin.form 。 Webseal 还返回一个 cookie,因此后续请求不必再次进行身份验证。
这意味着您需要发送 POST 请求:
block 引用>The POST must be made to /pkmslogin.form. The POST request body must contain the field data for three fields: username, password, login-form-type
The value of login-form-type must be "pwd" for forms logins. The content-length header must indicate the length of the resulting request body.
我在 .Net 中使用 HttpClient 完成了此操作。像这样的事情:
using (var httpClient = new HttpClient()) { // First post the authentication data var authenticationResult = httpClient.PostAsync("http://webseal/pkmslogin.form", new FormUrlEncodedContent( new Dictionary<string, string>() { {"username", "user"}, {"password", "pwd"}, {"login-form-type", "pwd"} } ) ).Result; // Now access our resource var webserviceResult = httpClient.GetAsync("http://webseal/webservice").Result; }
如果这不起作用,您可能需要获取 WebSeal 返回的 Cookie,并每次都发送该 Cookie。
关于reverse-proxy - 以编程方式访问托管在 WebSEAL 反向代理后面的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15116948/