Page 1 of 2

API Key Error

PostPosted: Tue Jan 07, 2020 2:27 pm
by SBarnes
Hi

https://api.jiwa.com.au/Queries/DB_Main ... uE-M8gBlA8

is producing the following error, our development server is getting the same response, how do we fix this?

In addition to this new custom route that is supposed to operate off a debtor api key is producing a screen asking for a Jiwa user name and password to login, saying that it needs to be authenticated?

Code: Select all
Response Status
Error CodeAggregateExceptionMessageOne or more errors occurred.Stack Traceat System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task`1.get_Result() at JiwaFinancials.Jiwa.JiwaServiceModel.JiwaApiKeyAuthProvider.Authenticate(IServiceBase authService, IAuthSession session, Authenticate request) in c:\ProgramData\Jiwa Financials\Jiwa 7\7.2.1\SYSTEM\JiwaSupportSQL3\ApiJiwaComAu\Plugins\Admin\Compile\REST API\REST API.cs:line 3039 at ServiceStack.Auth.AuthenticateService.Authenticate(Authenticate request, String provider, IAuthSession session, IAuthProvider oAuthConfig) at ServiceStack.Auth.AuthenticateService.Post(Authenticate request) at JiwaFinancials.Jiwa.JiwaServiceModel.JiwaApiKeyAuthProvider.PreAuthenticateWithApiKey(IRequest req, IResponse res, v_APIKey apiKey) in c:\ProgramData\Jiwa Financials\Jiwa 7\7.2.1\SYSTEM\JiwaSupportSQL3\ApiJiwaComAu\Plugins\Admin\Compile\REST API\REST API.cs:line 3141 at JiwaFinancials.Jiwa.JiwaServiceModel.JiwaApiKeyAuthProvider.PreAuthenticate(IRequest req, IResponse res) in c:\ProgramData\Jiwa Financials\Jiwa 7\7.2.1\SYSTEM\JiwaSupportSQL3\ApiJiwaComAu\Plugins\Admin\Compile\REST API\REST API.cs:line 3088 at ServiceStack.AuthenticateAttribute.PreAuthenticate(IRequest req, IEnumerable`1 authProviders) at ServiceStack.AuthenticateAttribute.<ExecuteAsync>d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at ServiceStack.ServiceStackHost.<ApplyRequestFiltersSingleAsync>d__317.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at ServiceStack.ServiceStackHost.<ApplyRequestFiltersAsync>d__316.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at ServiceStack.Host.RestHandler.<ProcessRequestAsync>d__14.MoveNext()

Re: API Key Error

PostPosted: Tue Jan 07, 2020 3:43 pm
by SBarnes
Further to this on the custom route it's actually the following line that is producing the error

Code: Select all
await manager.LogonAsync(StartupManager.Database.ServerName, StartupManager.Database.DatabaseName, apiKey.KeyValue);

and the inner exception in the debugger is

Code: Select all
Inner Exception 1:
InvalidCastException: Specified cast is not valid.


But using a staff api key for admin gets inside the code of a custom route which then catches the error that the api key is of the wrong type.

Re: API Key Error

PostPosted: Sun Jan 12, 2020 8:00 pm
by Mike.Sheen
Odd... I just restarted the service at https://api.jiwa.com.au/ and now that query works - I did get the same error as you reported before, however.

I shall look into it - but I'm keen to know if restarting it for you works also.

Re: API Key Error

PostPosted: Mon Jan 13, 2020 8:59 am
by SBarnes
Hi Mike,

Restarting makes no difference the call works with a staff api key and crashes with a debtor api key, in fact you can run them simultaneously and get the same result.

Interestingly though if you give the api an invalid key you get 404 not found and not a 403 error about unauthorised

Re: API Key Error

PostPosted: Mon Jan 13, 2020 3:54 pm
by Mike.Sheen
SBarnes wrote:Restarting makes no difference the call works with a staff api key and crashes with a debtor api key, in fact you can run them simultaneously and get the same result.


Debtor API key definitely was failing for me until I restarted the service on api.jiwa.com.au - I didn't test the staff API Key, but that is certainly working now - must be something different...

SBarnes wrote:Interestingly though if you give the api an invalid key you get 404 not found and not a 403 error about unauthorised


Are you getting that only through a browser, or are you also getting that when using code to call the API? I ask because if using a browser, by default we redirect you to a login page if you are unauthenticated and that error will occur if it cannot redirect to the login page.

Re: API Key Error

PostPosted: Mon Jan 13, 2020 8:12 pm
by SBarnes
Hi Mike,

In a browser but if you go to the link without the api key it does redirect to the login page.

Re: API Key Error

PostPosted: Tue Jan 14, 2020 4:26 pm
by SBarnes
Is there any update on why the debtor api keys aren't working?

Re: API Key Error

PostPosted: Tue Jan 14, 2020 4:31 pm
by Mike.Sheen
SBarnes wrote:Is there any update on why the debtor api keys aren't working?


No - I cannot reproduce the problem anymore. When you created this topic the link you provided which was failing (https://api.jiwa.com.au/Queries/DB_Main ... uE-M8gBlA8) I could see was throwing an exception, but after restarting the service it worked and is still working now.

Can you test with it configured to point to a demo database and see if you still have the error? If you don't then it might be a plugin perhaps causing the problem.

Re: API Key Error

PostPosted: Tue Jan 14, 2020 5:33 pm
by SBarnes
Hi Mike,

You were right and wrong at the same time, its not the database its the debtor, if I change the debtor it works. I will email you the xml for the debtor which might give you some idea.

Re: API Key Error

PostPosted: Wed Jan 15, 2020 8:58 am
by Mike.Sheen
SBarnes wrote:Hi Mike,

You were right and wrong at the same time, its not the database its the debtor, if I change the debtor it works. I will email you the xml for the debtor which might give you some idea.


Nothing about that debtor record appears to be the cause... but it's impossible to know for sure because there are references to other data I don't have - such as the custom fields originating from plugins I don't have.

The best way to solve this one is to provide a database - instructions on how to FTP it to us can be found here.

When that's uploaded, create a helpdesk ticket with the steps we need to take to repro and I'll pick it up from there.