Acess Docker Server from .netcore client

I have speckle v2 running on a docker. and I have a .netcore app, I try to make it connect to the server to get the account.

           var currentAccount = AccountManager.GetAccounts(serverUrl).FirstOrDefault();
            var SpeckleGraphClient = new Core.Api.Client(currentAccount);

The Account is always Null.

1 Like

Hi @Mark_Eskander :wave:t3:

Welcome back to the community!

I think your code looks a bit weird. When calling GetAccounts, you don’t need to specify the url of the server. The result will be an IEnumerable of all your local accounts. Then you can ToList() to enumerate them.

If what you are looking for is your “default” account. You can always use the GetDefaultAccount.
Here’s an image of how we are getting those on one of the nodes of the Grasshopper Connector.
Screenshot 2021-08-10 at 09.19.19

In your case you are calling GetAccounts().FirstOrDefault(), which can return null if there is no first nor default to return (meaning, the list may be empty?).

So,

  • first ensure that your Speckle Manager app has at least one account properly set up.
  • Then, try you code but just remove the input on GetAccounts(). To be honest, That should have thrown a compiler warning, as the GetAccounts() method doesn’t take any inputs.

Hope that fixes your problems.

On a side note, if you are looking to build apps that are not exclusively for Desktop computers (where users can have the Speckle Manager installed), I would suggest to look into our Authentication strategies using Tokens or Speckle Apps :+1:t3: you can find more info on how that works here:
https://speckle.guide/dev/apps-auth.html

2 Likes

Thank you for the fast reply.
I think the best approach is via Tokens or Speckle Apps. I will check the examples. Thank you.

1 Like

I thought so, considering you’re looking into a netcore app, which can virtually run anywhere :slight_smile:

We also have a guide to create a Speckle App, but that’s written in Vue (HTML/JS framework), so the code won’t be exactly the same, but the logic and endpoints used will be.

https://speckle.guide/dev/apps.html

Ping us if you struggle with anything else! And happy hacking!!

1 Like

Thank you again :slight_smile: will do.

1 Like