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

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

问题描述

目标:

我希望我的Web应用程序能够将我的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
    Content-Type: application/x-www-form-urlencoded
    POST Body:
        name:admin,
        pass:myadminpassword

但是它只会不断返回401未经授权的响应.我已经仔细检查过,并且身份验证信息正确无误.我已经尝试过对参数名称进行其他修改,例如:(用户名,密码),(用户,密码),(名称,密码)等.

我似乎无法使登录正常工作,并且我浏览了在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 '
{
    "username":"user",
    "password":"password"
}
'

所以:

  • 您的端点正常
  • 内容类型应为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天全站免登陆