如何通过HTTP访问ejabberd admin api? [英] How to access ejabberd admin api via HTTP?

查看:114
本文介绍了如何通过HTTP访问ejabberd admin api?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了



输入您的管理员详细信息,然后点击接受



然后在url中,您会发现这样的更改



http:// localhost: 5280 / oauth / authorization_token?access_token = Ra9W9aRgeoUgIpN0P68SIGDaatDIVcgB& token_type = bearer& expires_in = 3600& scope = get_roster%20connected_users& state =



看到 访问令牌在那里copyit并做一个卷曲来获得连接的用户。 (在您的终端中键入此命令)



curl -v POST -HX-Admin:true-H授权:承载Ra9W9aRgeoUgIpN0P68SIGDaatDIVcgB http:// localhost:5280 / api / connected_users -d'[]'



您将获得所有连接用户的Json响应。



这是你应该如何在ejabberd中调用API。希望这有助于:)


I read about the doc https://docs.ejabberd.im/admin/api/

And I wonder how can I access those API via HTTP. I tried to access but it always 404.

解决方案

In your ejabberd.yml you can find a configuration like this

- 
port: 5280
module: ejabberd_http
request_handlers:
  "/websocket": ejabberd_http_ws

Enable api and oauth,

- 
port: 5280
module: ejabberd_http
request_handlers:
  "/websocket": ejabberd_http_ws
  "/api": mod_http_api
  "/oauth": ejabberd_oauth

We are enabling api to have access from other programming languages(JSON request and response)

We are enabling oauth to raise an api request and get response(Without which if we access /api we will get only 401-unauthorized error)

Once this configuration in done, give a http request in your browser. URL must be

http://localhost:5280/oauth/authorization_token?response_type=token&client_id=Client1&scope=get_roster+connected_users

get_roster and connected_users are API end points Clinet1 is some name that you can give response_type must be always token

Once you hit it it will render a screen as this,

Enter your admin details and click on accept

Then in the url you will find a change something like this

http://localhost:5280/oauth/authorization_token?access_token=Ra9W9aRgeoUgIpN0P68SIGDaatDIVcgB&token_type=bearer&expires_in=3600&scope=get_roster%20connected_users&state=

You can see a access token there copyit and do a curl to get the connected users. (Type this command in your terminal)

curl -v POST -H "X-Admin: true" -H "Authorization: Bearer Ra9W9aRgeoUgIpN0P68SIGDaatDIVcgB" http://localhost:5280/api/connected_users -d '[]'

You will get a Json response with all connected users.

This is how you should make API calls in ejabberd. Hope this helps :)

这篇关于如何通过HTTP访问ejabberd admin api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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