m1k1o / neko

A self hosted virtual browser that runs in docker and uses WebRTC.
https://neko.m1k1o.net/
Apache License 2.0
7.74k stars 569 forks source link

Can I Kick or Ban someone from the room through the API? #441

Closed z2labplus closed 2 days ago

z2labplus commented 2 weeks ago

Can I Kick or Ban someone from the room through the API? or Can I make someone in the room lose control through an API? image

m1k1o commented 2 weeks ago

In v3 yes and yes, it will be possible. For current implementation not easily, you would need to connect to websocket as another user.

z2labplus commented 1 week ago

in the neko v3 or neko-rooms v3 ? and the v3 is release?

m1k1o commented 1 week ago

In neko v3, neko rooms works with both. Its on the v3 branch.

z2labplus commented 1 week ago

what different about with the v3 and v3-phase1?

z2labplus commented 1 week ago

1731552847266 when I git clone v3 I run the neko/client/dev/serve neko/server/dev/start

not the chrome?

m1k1o commented 1 week ago

what different about with the v3 and v3-phase1?

Its all explained in https://github.com/m1k1o/neko/issues/371

not the chrome?

It is meant only for development. But you could replace directory server/dev/runtime/ with .docker/google-chrome/ and then rebuild, to get it working even for development.

z2labplus commented 1 week ago

Thanks very much! Can we add users through APIs? Delete user? ban user ?

m1k1o commented 1 week ago

In v3 yes. You can copy the openapi.yaml to some editor like https://swagger.io and it shows you interactively what APIs are available.

z2labplus commented 4 days ago

I use the https://app.swaggerhub.com/apis/Z858570636/n-eko_rest_api/1.0.0#/members/membersCreate 1731893751261

but it show the error

{
  "code": 401,
  "message": "Unauthorized"
}

1731893842074

how to add the token

m1k1o commented 4 days ago

You need to perform login, one of the first api calls. And then there is probably possibly to set the token in swagger. https://stackoverflow.com/questions/32910065/how-to-use-authorization-bearer-token-in-a-swagger-spec

z2labplus commented 4 days ago

I use the /api/login

1731922530245

and then get the response

1731922555137

and then use the token

{
  "id": "admin-tRjjT",
  "token": "VBPykToh-HpB7Yuw-gDRMkoutYmatJriI-IC6BE9iqmy3Bs6sM8lhRTbI83CdoRs",
  "profile": {
    "name": "admin",
    "is_admin": false,
    "can_login": true,
    "can_connect": true,
    "can_watch": true,
    "can_host": true,
    "can_share_media": true,
    "can_access_clipboard": true,
    "sends_inactive_cursor": true,
    "can_see_inactive_cursors": false,
    "plugins": null
  },
  "state": {
    "is_connected": false,
    "is_watching": false
  }
}

and then use the

1731922625128

import requests

url = "http://74.48.86.124:3000/api/members"

token = "VBPykToh-HpB7Yuw-gDRMkoutYmatJriI-IC6BE9iqmy3Bs6sM8lhRTbI83CdoRs"
headers = {
    "Authorization": f"Bearer {token}"
}

data = {
  "username": "admin",
  "password": "neko",
  "profile": {
    "name": "bill",
    "is_admin": False,
    "can_login": True,
    "can_connect": True,
    "can_watch": True,
    "can_host": True,
    "can_share_media": True,
    "can_access_clipboard": True,
    "sends_inactive_cursor": True,
    "can_see_inactive_cursors": True,
    "plugins": {
      "additionalProp1": {}
    }
  }
}
response = requests.post(url, headers=headers, json=data)

print(response.status_code)
print(response.text)

but I get the result

1731922678543

403
{"code":403,"message":"session is not admin"}
request failed (401): Unauthorized error="no authentication provided" 

I say the admin account not the admin, another account ? how to solve it ?

m1k1o commented 4 days ago

As you can see in your details, the user is not admin, so he cannot list members. image

By default the login is done the same way as in the neko v2, where you have a single password for admin and a single password for user. When you use this password it creates a new profile based on that. It looks like you used password neko that is probably assigned to user profile. Even though you used username admin its just a display name that can be anything. Try using the adming password.

z2labplus commented 4 days ago

I use the

username:admin
password:admin

to get the token

and send the request

import requests

url = "http://74.48.86.124:3000/api/members"

token = "nzw_3LufSXeiUQeOunmpjwo71L3smIp8qql6Q208yMk_OhgMH0z2sGaXGRgTougk"
headers = {
    "Authorization": f"Bearer {token}"
}

data = {
  "username": "user2",
  "password": "password2",
  "profile": {
    "name": "bill2",
    "is_admin": True,
    "can_login": True,
    "can_connect": True,
    "can_watch": True,
    "can_host": True,
    "can_share_media": True,
    "can_access_clipboard": True,
    "sends_inactive_cursor": True,
    "can_see_inactive_cursors": True,
    "plugins": {
      "additionalProp1": {}
    }
  }
}
response = requests.post(url, headers=headers, json=data)

print(response.status_code)
print(response.text)

but it still can not to create the new user,it raise the error

ERR request failed (500): Internal Server Error error="new user is created on first login in multiuser mode" how to solve it?

m1k1o commented 4 days ago

By default, there is multiuser mode meaning that new users are created when logging in. You can switch to other user mode and then you need to create your own users.

Add this to env:

NEKO_SESSION_API_TOKEN="yourApiTokenCanBeAnything"
NEKO_MEMBER_PROVIDER="object"

You will now need to create your own users and you can delete/manage them. By default you will have no users when starting neko, and you can use the specified access token to create these users.

Or you can preserve your logins by using file provider. All users will be saved to specified json file. You must then mount it outside of container to have it available when recreated.

NEKO_MEMBER_PROVIDER="file"
NEKO_MEMBER_FILE_PATH="/path/to/members.json"
z2labplus commented 4 days ago

add this NEKO_SESSION_API_TOKEN="yourApiTokenCanBeAnything" NEKO_MEMBER_PROVIDER="object" to the .docker/.env.default file ?

m1k1o commented 4 days ago

If you use dev scripts then you need to directly modify start script. You will see there are other environment variables and you need to add it to them.

z2labplus commented 3 days ago

I motify the file server/dev/start 1732022793563 and run the server/dev/start and I request again,it also show me the error new user is created on first login in noauth mode" how to solve it ? also can not throught the api to create new user

m1k1o commented 3 days ago

The issue is probably your additional quotes'. It looks like neko parses the string as 'object' with the quotes, and it cannot find it so it fallbacks to noauth mode. Remove it as well from token.

So it should look like this:

-e "NEKO_SESSION_API_TOKEN=yourApiTokenCanBeAnything" \
-e "NEKO_MEMBER_PROVIDER=object" \
z2labplus commented 2 days ago

it works,thanks a lot!