Authenticating App in C#

How do I authenticate my app in C#? I get a StackOverFlow exception with the below code. I would not expect this exception regardless of the parameters I supply.

Preformatted textvar authResponse = Session.AuthenticateAppAsync(new AppExchangeInfo() {Id = "test.app"}, "http://localhost:33000");

Hey @JeromeBell,

To authenticate the app, you will have to run the authd (authentication daemon from the CLI) first and login to the account. After that you can use this API and you will get the authentication request in the CLI. Once you allow the request then you will get the response from the C# API. Also please add the appName and vendor field values as well in the AppExchangeInfo object.

You can also use the SNAPP desktop for the same process.

1 Like

Here’s my modified code.

var authResponse = await Session.AuthenticateAppAsync( new AppExchangeInfo() { Id = "test.app", Name = "My App", Vendor = "Jerome Bell" }, "http://localhost:443");

I believe the address is accurate based on these Vault connection strings

The address/endpoint you are passing should be authd’s endpoint not the vaults. You can check the docs here for running the auth daemon and logging in for the authentication: https://github.com/maidsafe/safe-api/tree/master/safe-cli#the-authenticator-daemon-authd

I’m using the following code now, which uses the safe-authd endpoint that corrsesponds to the Task Manager image

            var authResponse = await Session.AuthenticateAppAsync(
            new AppExchangeInfo()
            {
                Id = appId,
                Name = "My App",
                Vendor = "Jerome Bell"
            },
            "https://localhost:33000");

I do NOT get a StackOverflowException. I see the request via “safe auth reqs”, I authorize the request via safe-cli. Afterwards I do NOT see any requests after invoking “safe auth reqs”. I conclude that I am successfully authorizing the request. However, I am now getting the following exception

SafeApp.Core.FfiException
HResult=0x80131500
Message=Error Code: -600. Description: [Error] AuthdClientError - [Error] ClientError - Response not received: read error
Source=mscorlib
StackTrace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at safeapp.netframework.Program.d__0.MoveNext() in C:\src\safeapp\safeapp.netframework\Program.cs:line 34
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at safeapp.netframework.Program.(String[] args)

It seems the issue is coming from the native libs itself but not from the C# API. I will give it a try and see if I’m seeing the same issue. Maybe in mean time you can continue with the mock APIs for testing purposes.