How to use admin REST API in xamarin application to create new users?

I am creating a xamarin mobile application and I want to create new users from the mobile application , I know I can create users from sync gateway configuration or from admin REST API ,
I tried to use the admin REST API in the application but I got Java.Net.SocketTimeoutException

so how can I use the admin REST API to create users in the application ?

Can you confirm that the POST {db}/_user/ call works from curl or Postman?
The exception indicates that the app cannot connect to Sync Gateway so the call is timing out.

Cross-posting from StackOverflow: authentication - How to use admin REST API in Xamarin application to create new users in couchbase sync gateway? - Stack Overflow

In Sync Gateway, port 4985 is intentionally not public by default. Opening it allows anybody full access to your data.

  1. Integrate with a third-party authentication provider using OpenID Connect. You can configure these to create users on-demand when they sign in. User Authentication | Couchbase Docs

  2. Write your own small service that can take new user requests from your app, which then calls out to a firewalled Sync Gateway Admin API. User Authentication | Couchbase Docs

“create service that can take new user requests from your app” => can you please more explain this part , Thanks . – Maria Nabil Jan 5 at 14:51

You’ll have to write your own API that can take public new user requests that your app can call.

This should be running somewhere that can talk to the Admin API port without exposing it publically. For example, the same host and use localhost:4985, or a firewall rule to allow your service admin access.

You can effectively handle it by define a connection timeout and later handle it by using a try-catch block. From the client side you can use the following method and set the timeout parameter:

clientSocket.connect(SocketAddress,timeout)

From the server side you can use the following method and set the timeout parameter:

serverSocket.setSoTimeout(timeout)

Also, if you are a programmer, you can surround the socket connection part of your code in a java try/catch/finally and handle the error in the catch. You might try connecting a second time, or try connecting to another possible socket, or simply exit the program cleanly.