使用服务模块远程登录 Drupal 7 站点 [英] Login remotely to Drupal 7 site using services module

查看:28
本文介绍了使用服务模块远程登录 Drupal 7 站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:

我希望我的网络应用能够将用户在我的 Drupal 站点上的用户名和密码发送到 Drupal 站点,并让 Drupal 站点响应并确认用户身份验证信息是否正确.

另一个需要是让 Drupal 服务器为创建的会话返回一个会话 ID,以及用户的信息,如电子邮件、用户角色等.

我目前拥有的:

我已启用 Services Rest Server,并在 www.mysite.com/rest/上创建了一个端点.我已将响应格式设置为仅 json,并将解析器请求到 application/x-www-form-urlencoded.我已经通过会话、调试模式打开了身份验证.我还确保为此端点启用整个用户资源.导航到 www.mysite.com/rest/user 确实会给我一个所有用户的列表.

关于我的身份验证尝试,我尝试发送请求:

POST www.mysite.com/rest/user/login内容类型:应用程序/x-www-form-urlencodedPOST 正文:姓名:管理员,通过:我的管理员密码

但它只是不断返回 401 Unauthorized 响应.我已经仔细检查过,认证信息是正确的.我尝试了参数名称的其他变体,例如:(用户名、密码)、(用户、密码)、(名称、密码)等.

我似乎无法让登录正常工作,我已经查看了我在 Stackoverflow 上找到的其他示例,但它们没有工作.

解决方案

drupal.org 中有关于服务模块的很好的文档.特别是这里有几个使用服务的例子:http://drupal.org/node/783722>

此页面上的示例使用命令行工具 curl:http://drupal.org/node/1795770

并包含一个登录示例:

curl -X POST -i -H "Content-type: application/json" -c cookies.txt -X POST http://localhost:8888/service/user/login -d '{"用户名":"用户",密码":密码"}'

所以:

  • 你的端点没问题
  • 内容类型应该是 application/json
  • 正文应该类似于 { "username":"admin", "password":"pass" }

GOAL:

I want my web app to be able to send username and password of a user on my Drupal site, to the Drupal site and have the Drupal site respond with confirmation of whether the user authentication information is correct.

Another need is to have the Drupal server return a session id for a session created, and information for the user, like email, user role, etc.

What I have so far:

I've enabled Services Rest Server, and created an endpoint at www.mysite.com/rest/. I've set the response format to json only, and request parser to application/x-www-form-urlencoded. I've turned on authentication by session, debugging mode. I've also made sure to enable the entire user resource for this endpoint. Navigating to www.mysite.com/rest/user does give me a list of all users.

Regarding my attempts with authentication, I've tried sending requests:

POST www.mysite.com/rest/user/login
    Content-Type: application/x-www-form-urlencoded
    POST Body:
        name:admin,
        pass:myadminpassword

But it just keeps returning a 401 Unauthorized response. I've double checked and the auth information is correct. I've tried other variations on parameter names like: (username, password), (user, pass), (name, password), etc.

I can't seem to get the login to work and I've looked through other examples I've found on Stackoverflow but they haven't worked.

解决方案

There is good documentation for the services module in drupal.org. Particulary there are several examples for using servicers here: http://drupal.org/node/783722

The example on this page is using command line tool curl: http://drupal.org/node/1795770

And contains one example for login:

curl -X POST -i -H "Content-type: application/json" -c cookies.txt -X POST http://localhost:8888/service/user/login -d '
{
    "username":"user",
    "password":"password"
}
'

So:

  • you have your endpoint ok
  • Content-type should be application/json
  • and the body should be something like { "username":"admin", "password":"pass" }

这篇关于使用服务模块远程登录 Drupal 7 站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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