How to access ejabberd admin api via HTTP?

前端 未结 2 1032
庸人自扰
庸人自扰 2021-01-05 18:05

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.

相关标签:
2条回答
  • 2021-01-05 18:47

    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 :)

    0 讨论(0)
  • 2021-01-05 18:49

    enable ejabberd_xmlrpc in ejabberd.yml file uncomment the following lines-

    ## To handle XML-RPC requests that provide admin credentials:
      ##
      ## - 
      ##   port: 4560
      ##   module: ejabberd_xmlrpc
      ##   maxsessions: 10
      ##   timeout: 5000
      ##   access_commands:
      ##     xmlrpc:
      ##       commands: all
      ##   options: []
    

    All XMLRPC are send to the following URL: http://host:4560/. for more detail check here

    0 讨论(0)
提交回复
热议问题