processone / ejabberd-contrib

Growing and curated ejabberd contributions repository - PR or ask to join !
http://ejabberd.im
248 stars 137 forks source link

ejabberd_auth_http not making request #292

Closed dabslants closed 3 years ago

dabslants commented 3 years ago

I have ejabberd 20.07 installed on ubuntu using the binary installer and installed the module using the ejabberdctl commands. User authentication fails when set to http. But sql & external auth methods works. Log level 5 does not log any Request/Response log as declared in the code.

dabslants commented 3 years ago

This is all that was logged when I attempted to sign in:

2020-08-14 15:34:56.396 [info] <0.384.0>@ejabberd_listener:accept:273 (<0.583.0>) Accepted connection [::ffff:127.0.0.1]:55918 -> [::ffff:127.0.0.1]:5222
2020-08-14 15:34:56.399 [info] <0.583.0> (tcp|<0.583.0>) Received XML on stream = <<"<?xml version='1.0' ?><stream:stream to='localhost' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>">>
2020-08-14 15:34:56.407 [info] <0.583.0> (tcp|<0.583.0>) Send XML on stream = <<"<?xml version='1.0'?><stream:stream id='16573359300420493073' version='1.0' xml:lang='en' xmlns:stream='http://etherx.jabber.org/streams' from='localhost' xmlns='jabber:client'>">>
2020-08-14 15:34:56.409 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_stream_started: mod_client_state:c2s_stream_started/2
2020-08-14 15:34:56.409 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_stream_started: mod_stream_mgmt:c2s_stream_started/2
2020-08-14 15:34:56.409 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_stream_started: mod_fail2ban:c2s_stream_started/2
2020-08-14 15:34:56.409 [info] <0.583.0> (tcp|<0.583.0>) Send XML on stream = <<"<stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls></stream:features>">>
2020-08-14 15:34:56.409 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_push:c2s_stanza/3
2020-08-14 15:34:56.409 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_push_keepalive:c2s_stanza/3
2020-08-14 15:34:56.409 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_stream_mgmt:c2s_handle_send/3
2020-08-14 15:34:56.410 [info] <0.583.0> (tcp|<0.583.0>) Received XML on stream = <<"<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>">>
2020-08-14 15:34:56.410 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_recv: mod_stream_mgmt:c2s_handle_recv/3
2020-08-14 15:34:56.411 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_push:c2s_stanza/3
2020-08-14 15:34:56.411 [info] <0.583.0> (tcp|<0.583.0>) Send XML on stream = <<"<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>">>
2020-08-14 15:34:56.411 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_push_keepalive:c2s_stanza/3
2020-08-14 15:34:56.411 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_stream_mgmt:c2s_handle_send/3
2020-08-14 15:34:56.474 [info] <0.583.0> (tls|<0.583.0>) Received XML on stream = <<"<stream:stream to='localhost' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>">>
2020-08-14 15:34:56.474 [info] <0.583.0> (tls|<0.583.0>) Send XML on stream = <<"<?xml version='1.0'?><stream:stream id='3039575738572621434' version='1.0' xml:lang='en' xmlns:stream='http://etherx.jabber.org/streams' from='localhost' xmlns='jabber:client'>">>
2020-08-14 15:34:56.474 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_stream_started: mod_client_state:c2s_stream_started/2
2020-08-14 15:34:56.474 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_stream_started: mod_stream_mgmt:c2s_stream_started/2
2020-08-14 15:34:56.474 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_stream_started: mod_fail2ban:c2s_stream_started/2
2020-08-14 15:34:56.478 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_pre_auth_features: mod_register:stream_feature_register/2
2020-08-14 15:34:56.482 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_push:c2s_stanza/3
2020-08-14 15:34:56.482 [info] <0.583.0> (tls|<0.583.0>) Send XML on stream = <<"<stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism>X-OAUTH2</mechanism></mechanisms><register xmlns='http://jabber.org/features/iq-register'/></stream:features>">>
2020-08-14 15:34:56.482 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_push_keepalive:c2s_stanza/3
2020-08-14 15:34:56.482 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_stream_mgmt:c2s_handle_send/3
2020-08-14 15:34:56.483 [info] <0.583.0> (tls|<0.583.0>) Received XML on stream = <<"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN' xmlns:ga='http://www.google.com/talk/protocol/auth' ga:client-uses-full-bind-result='true'>AGRhYnMAbGFybnRlcm4=</auth>">>
2020-08-14 15:34:56.483 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_recv: mod_stream_mgmt:c2s_handle_recv/3
2020-08-14 15:34:56.490 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_auth_result: ejabberd_c2s:process_auth_result/3
2020-08-14 15:34:56.490 [warning] <0.583.0>@ejabberd_c2s:process_auth_result:276 (tls|<0.583.0>) Failed c2s PLAIN authentication for user1@localhost from ::ffff:127.0.0.1: Invalid username or password
2020-08-14 15:34:56.490 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_auth_result: mod_fail2ban:c2s_auth_result/3
2020-08-14 15:34:56.491 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_push:c2s_stanza/3
2020-08-14 15:34:56.491 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_push_keepalive:c2s_stanza/3
2020-08-14 15:34:56.491 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_handle_send: mod_stream_mgmt:c2s_handle_send/3
2020-08-14 15:34:56.491 [info] <0.583.0> (tls|<0.583.0>) Send XML on stream = <<"<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><not-authorized/><text xml:lang='en'>Invalid username or password</text></failure>">>
2020-08-14 15:34:56.495 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_closed: mod_stream_mgmt:c2s_closed/2
2020-08-14 15:34:56.495 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_closed: ejabberd_c2s:process_closed/2
2020-08-14 15:34:56.495 [info] <0.583.0> (tls|<0.583.0>) Received XML on stream = <<"</stream:stream>">>
2020-08-14 15:34:56.495 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_terminated: mod_stream_mgmt:c2s_terminated/2
2020-08-14 15:34:56.495 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_terminated: mod_pubsub:on_user_offline/2
2020-08-14 15:34:56.495 [debug] <0.583.0>@ejabberd_hooks:safe_apply:231 Running hook c2s_terminated: ejabberd_c2s:process_terminated/2
2020-08-14 15:34:56.495 [info] <0.583.0> (tls|<0.583.0>) Send XML on stream = <<"</stream:stream>">>
dabslants commented 3 years ago

My config file:

hosts:
  - "localhost"

loglevel: 5
log_rotate_size: 10485760
log_rotate_date: ""
log_rotate_count: 1
log_rate_limit: 100

new_sql_schema: true

sql_type: mysql
sql_server: "localhost"
sql_database: "ejabberd"
sql_username: "cccc
sql_password: "cccc"
sql_pool_size: 5
sql_port: 3306

default_db: sql

auth_use_cache: false
auth_password_format: plain 
auth_method: http
auth_opts:
  host: "http://localhost:5010"
  connection_pool_size: 10
  connection_opts: []
  basic_auth: ""
  path_prefix: "/auth/"

certfiles:
  - "/home/ejabberd-20.07/conf/server.pem"
##  - "/etc/letsencrypt/live/localhost/fullchain.pem"
##  - "/etc/letsencrypt/live/localhost/privkey.pem"

ca_file: "/home/ejabberd-20.07/conf/cacert.pem"

listen:
  -
    port: 5222
    ip: "::"
    module: ejabberd_c2s
    max_stanza_size: 262144
    shaper: c2s_shaper
    access: c2s
    starttls_required: true
  -
    port: 5269
    ip: "::"
    module: ejabberd_s2s_in
    max_stanza_size: 524288
  -
    port: 5443
    ip: "::"
    module: ejabberd_http
    tls: true
    request_handlers:
      "/admin": ejabberd_web_admin
      "/api": mod_http_api
      "/bosh": mod_bosh
      "/captcha": ejabberd_captcha
      "/upload": mod_http_upload
      "/ws": ejabberd_http_ws
      "/oauth": ejabberd_oauth
  -
    port: 5280
    ip: "::"
    module: ejabberd_http
    request_handlers:
      "/admin": ejabberd_web_admin
  -
    port: 1883
    ip: "::"
    module: mod_mqtt
    backlog: 1000

s2s_use_starttls: optional

acl:
  local:
    user_regexp: ""
  loopback:
    ip:
      - 127.0.0.0/8
      - ::1/128
      - ::FFFF:127.0.0.1/128
  admin:
    user:
      - "admin@localhost"

access_rules:
  local:
    allow: local
  c2s:
    deny: blocked
    allow: all
  announce:
    allow: admin
  configure:
    allow: admin
  muc_create:
    allow: local
  pubsub_createnode:
    allow: local
  trusted_network:
    allow: loopback

api_permissions:
  "console commands":
    from:
      - ejabberd_ctl
    who: all
    what: "*"
  "admin access":
    who:
      access:
        allow:
          acl: loopback
          acl: admin
      oauth:
        scope: "ejabberd:admin"
        access:
          allow:
            acl: loopback
            acl: admin
    what:
      - "*"
      - "!stop"
      - "!start"
  "public commands":
    who:
      ip: 127.0.0.1/8
    what:
      - status
      - connected_users_number

shaper:
  normal: 1000
  fast: 50000

shaper_rules:
  max_user_sessions: 10
  max_user_offline_messages:
    5000: admin
    100: all
  c2s_shaper:
    none: admin
    normal: all
  s2s_shaper: fast

max_fsm_queue: 10000

acme:
   contact: "mailto:admin@localhost"
   ca_url: "https://acme-v01.api.letsencrypt.org"

modules:
  mod_adhoc: {}
  mod_admin_extra: {}
  mod_announce:
    access: announce
  mod_avatar: {}
  mod_blocking: {}
  mod_bosh: {}
  mod_caps: {}
  mod_carboncopy: {}
  mod_client_state: {}
  mod_configure: {}
  mod_disco: {}
  mod_fail2ban: {}
  mod_http_api: {}
  mod_http_upload:
    put_url: https://@HOST@:5443/upload
  mod_last: {}
  mod_mam:
    ## Mnesia is limited to 2GB, better to use an SQL backend
    ## For small servers SQLite is a good fit and is very easy
    ## to configure. Uncomment this when you have SQL configured:
    ## db_type: sql
    assume_mam_usage: true
    default: never
  mod_mqtt: {}
  mod_muc:
    access:
      - allow
    access_admin:
      - allow: admin
    access_create: muc_create
    access_persistent: muc_create
    access_mam:
      - allow
    default_room_options:
      allow_subscription: true  # enable MucSub
      mam: false
  mod_muc_admin: {}
  mod_offline:
    access_max_user_messages: max_user_offline_messages
  mod_ping: {}
  mod_privacy: {}
  mod_private: {}
  mod_proxy65:
    access: local
    max_connections: 5
  mod_pubsub:
    access_createnode: pubsub_createnode
    plugins:
      - flat
      - pep
    force_node_config:
      ## Avoid buggy clients to make their bookmarks public
      storage:bookmarks:
        access_model: whitelist
  mod_push: {}
  mod_push_keepalive: {}
  mod_register:
    ## Only accept registration requests from the "trusted"
    ## network (see access_rules section above).
    ## Think twice before enabling registration from any
    ## address. See the Jabber SPAM Manifesto for details:
    ## https://github.com/ge0rg/jabber-spam-fighting-manifesto
    ip_access: trusted_network
  mod_roster:
    versioning: true
  mod_s2s_dialback: {}
  mod_shared_roster: {}
  mod_stream_mgmt:
    resend_on_timeout: if_offline
  mod_vcard: {}
  mod_vcard_xupdate: {}
  mod_version:
    show_os: false

### Local Variables:
### mode: yaml
### End:
### vim: set filetype=yaml tabstop=8
dabslants commented 3 years ago

Got it fixed. The issue was the response was having a '\n' appended to its end. Make sure the response body is a true (string/boolean) exactly in that case, else it fails.