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

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

Closed
z2labplus opened this issue Nov 5, 2024 · 19 comments
Closed

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

z2labplus opened this issue Nov 5, 2024 · 19 comments
Milestone

Comments

@z2labplus
Copy link

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
Copy link
Owner

m1k1o commented Nov 7, 2024

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

@m1k1o m1k1o changed the title Can I Kick or Ban someone from the room through the API? Can I Kick or Ban someone from the room through the API? Nov 7, 2024
@m1k1o m1k1o added this to n.eko v3 Nov 7, 2024
@m1k1o m1k1o added this to the n.eko v3 milestone Nov 7, 2024
@z2labplus
Copy link
Author

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

@m1k1o
Copy link
Owner

m1k1o commented Nov 13, 2024

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

@z2labplus
Copy link
Author

what different about with the v3 and v3-phase1?

@z2labplus
Copy link
Author

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

not the chrome?

@m1k1o
Copy link
Owner

m1k1o commented Nov 14, 2024

what different about with the v3 and v3-phase1?

Its all explained in #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
Copy link
Author

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

@m1k1o
Copy link
Owner

m1k1o commented Nov 14, 2024

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
Copy link
Author

z2labplus commented Nov 18, 2024

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
Copy link
Owner

m1k1o commented Nov 18, 2024

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
Copy link
Author

z2labplus commented Nov 18, 2024

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
Copy link
Owner

m1k1o commented Nov 18, 2024

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
Copy link
Author

z2labplus commented Nov 18, 2024

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
Copy link
Owner

m1k1o commented Nov 18, 2024

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
Copy link
Author

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

@m1k1o
Copy link
Owner

m1k1o commented Nov 18, 2024

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
Copy link
Author

z2labplus commented Nov 19, 2024

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
Copy link
Owner

m1k1o commented Nov 19, 2024

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
Copy link
Author

it works,thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants