board logo
WUICTeam
  • WUICTeam
  • 100% (Exalted)
  • Newbie Topic Starter
6 days ago
Question
https://crm.example.com/api/invoices/reminders [/c], which is an endpoint of the same app. The job runs, but the endpoint answers 401. Calling it by hand with a logged-in user works. What is going on?

Answer
The scheduler sends its __scheduler login and cookie only to the backend it is running in. An absolute URL that points to your public host name is, for the scheduler, just another server: the call is made without credentials, so a protected endpoint answers 401.

What counts as "this backend"
  • a loopback host (for example localhost) on a port the process is listening on;
  • a URL listed in Scheduler.TrustedAuthBaseUrls: scheme, host and port must match (the path is not compared).


Two ways to fix it
  1. Use a relative URL. A path starting with / is resolved on the address of the running app, so the host name never appears in the job: POST /api/invoices/reminders. Without a verb the call is a POST.
  2. Keep the absolute URL and declare it as trusted in appsettings.json:

https://crm.example.com/CrmApp .

Pitfall
Relative URLs cannot leave the app: //host/..., backslashes and paths like /../OtherApp/... are rejected. Don't use them to reach another service; for that, use an absolute URL, knowing that no credentials will be sent.

Documentation: Scheduling