0

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 ?

Here in the code I am using :

        private async void CreateUserBtnClicked(object sender, EventArgs e)
    {
          HttpClient _client = new HttpClient(); //Creating a new instance of HttpClient. (Microsoft.Net.Http)
        content = "{\"Username\":\"user.com\",\"Password\":\"123456\"}";
        string url = "http://<server_ip>:4985/user/";
        var request = await _client.PostAsync(url, new StringContent(content, Encoding.UTF8, "application/json"));
    }
Maria Nabil
  • 139
  • 1
  • 10
  • what is "http://jsonplaceholder.typicode.com/posts" for? – Matthew Groves Jan 02 '20 at 16:30
  • Are you sure port 4985 is accessible from the Xamarin app? Also, I'm assuming the username, password, and server_ip in this example are not what you are actually using? – Matthew Groves Jan 02 '20 at 16:31
  • @MatthewGroves I have edited my question , no I am not sure that port 4985 is accessible from the Xamarin app , but I should use it to create a new user and I don't know what is its alternative , I have hidden the server_ip in the question for security reasons – Maria Nabil Jan 05 '20 at 10:19

1 Answers1

2

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. https://docs.couchbase.com/sync-gateway/current/authentication.html#openid-connect

  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. https://docs.couchbase.com/sync-gateway/current/authentication.html#custom-authentication

bbrks
  • 136
  • 1
  • 2
  • "create service that can take new user requests from your app" => can you please more explain this part , Thanks . – Maria Nabil Jan 05 '20 at 14:51
  • @MariaNabil This [blog](https://blog.couchbase.com/custom-authentication-with-couchbase-mobile/) discusses the custom authentication option with example – rajagp Jan 13 '20 at 17:09