Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot register bot client #107

Closed
LecrisUT opened this issue Dec 30, 2020 · 4 comments
Closed

Cannot register bot client #107

LecrisUT opened this issue Dec 30, 2020 · 4 comments

Comments

@LecrisUT
Copy link

I have tried using the documented method of registering the bot client with ./bin/mbc auth --register, but I get the following error:

10:57:56ERRORserverError in handler
10:57:56ERRORserverTraceback (most recent call last):
  File "/opt/synapse/bots/maubot/lib64/python3.6/site-packages/maubot/management/api/middleware.py", line 43, in error
    return await handler(request)
  File "/opt/synapse/bots/maubot/lib64/python3.6/site-packages/maubot/management/api/client_auth.py", line 91, in register
    res = await api.request(Method.GET, Path.admin.register)
  File "/opt/synapse/bots/maubot/lib64/python3.6/site-packages/mautrix/api.py", line 208, in request
    return await self._send(method, endpoint, content, query_params, headers or {})
  File "/opt/synapse/bots/maubot/lib64/python3.6/site-packages/mautrix/api.py", line 149, in _send
    errcode=errcode, message=message)
mautrix.errors.request.MUnrecognized: Unrecognized request

I've tried accessing the url manually at _matrix/client/r0/register and _matrix/client/r0/admin/register I get the same Unrecognized request. Sorry I can't debug further as I'm unfamiliar with how to interface with APIs. At least I believe the former does not work because I've disabled user registration, and I can't find any documentation of the latter to check if I can manually invoke it.

I see this problem is related to #88 and other issues.

@ggogel
Copy link
Contributor

ggogel commented Dec 30, 2020

The mbc auth didn't work for me either. I think in my case the issue was that my reverse proxy forwards everything with /_matrix/* to synapse but mbc auth runs against /_matrix/maubot. This will also break if you change the base url of maubot.

Anyway, I worked my way around by using curl.

curl -X POST --header 'Content-Type: application/json' -d '{
    "identifier": { "type": "m.id.user", "user": "USERNAME" },
    "password": "PASSWORD",
    "type": "m.login.password"
}' 'https://MATRIXHOSTNAME/_matrix/client/r0/login'

Replace USERNAME, PASSWORD and MATRIXHOSTNAME according to your configuration. The server should reply with a .json containing the access token.

@LecrisUT
Copy link
Author

LecrisUT commented Dec 30, 2020

For me, the reverse-proxy is set correct, i.e. I can access both the matrix server and maubot manager. Login seems to be accessible, but the registration is not.

Using curl POST on _matrix/client/r0/register I get a session and some other JSON output, while _matrix/client/r0/admin/register gives the usual Unrecognized request.
I've tried editing with and without admin in the url, but both give Unrecognized request and I don't see directly where the registration_shared_secret is included in the payload.

res = await api.request(Method.GET, Path.admin.register)
nonce = res["nonce"]
mac = generate_mac(secret, nonce, username, password, user_type=user_type)
try:
return web.json_response(await api.request(Method.POST, Path.admin.register, content={
"nonce": nonce,
"username": username,
"password": password,
"admin": False,
"mac": mac,
# Older versions of synapse will ignore this field if it is None
"user_type": user_type,
}))

Edit: looking more into that python file, it looks like it first need to GET a response from which to generate the POST, however if I try to GET at the same URL, there's only Unrecognized request

@ggogel
Copy link
Contributor

ggogel commented Dec 30, 2020

Not _matrix/client/r0/register but _matrix/client/r0/login. It'll reply with a couple of variables including "access_token", which is what you need.

@LecrisUT
Copy link
Author

Ok so alternatively, I can manually create the users, log them in and get the access_token. Problem is I am using OAuth to login, and I don't see an option to add a password while logged in in order to interface like that.

@tulir tulir closed this as completed in 543f8db Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants