plneto / Synology.Api.Client

.NET/C# client for the Synology API
MIT License
21 stars 13 forks source link

Login fails (wrong path) #6

Closed FroggieFrog closed 1 year ago

FroggieFrog commented 1 year ago

I had to adjust the Path for AuthApi. According to the official document the path is auth.cgi instead of entry.cgi.

Workaround:

const string dsmUrl = "http://192.168.0.1:5001/";

var client = new SynologyClient(dsmUrl);

//the actual workaround
client .ApisInfo.AuthApi.Path = "auth.cgi";

await client.LoginAsync("username", "password");
plneto commented 1 year ago

This path was updated in the last version. See the issue and PR below

https://github.com/plneto/Synology.Api.Client/issues/3 https://github.com/plneto/Synology.Api.Client/pull/4

I tested both auth.cgi and entry.cgi on version DSM 7.1.1-42962 Update 3 and I was able to login.

What version of DSM do you use? Do you know more about how these paths work? There seems to be an inconsistency in the documentation between the different PDFs FileStation API Guide, DownloadStation API Guide, and Login Web API Guide

FroggieFrog commented 1 year ago

Actually there seems to be a difference between DSM 6 and 7. A DSM 6 version required auth.cgi and a DSM 7 version required entry.cgi.

I fixed it by checking the available API information and changing the path if necessary. Maybe this could be implemented int his library?

var apiInfo = await _synologyClient.InfoApi().QueryAsync();
if (!string.Equals(apiInfo.AuthApi.Path, _synologyClient.ApisInfo.AuthApi.Path, StringComparison.OrdinalIgnoreCase))
{
    _synologyClient.ApisInfo.AuthApi.Path = apiInfo.AuthApi.Path;
}
plneto commented 1 year ago

I've modified the code so it always uses the paths from the InfoApi response for all APIs. This should fix the problem for everyone. Let me know if it doesn't work for you.