openiddict / openiddict-samples

.NET samples for OpenIddict

Home Page:https://documentation.openiddict.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does ZirkuClient1 (InteractiveService) call to AuthenticateInteractivelyAsync need to be on a background service

dgxhubbard opened this issue · comments

Confirm you've already contributed to this project or that you sponsor it

  • I confirm I'm a sponsor or a contributor

Version

4.x

Question

For the OpenIdDict client, I am trying to get an access token from the server, using Zirku.Client1 as an example. However, that sample and the other samples that call AuthenticateInteractivelyAsync, do so on a background service. The client I am trying to build should be a console app, get the access token and then use it. Does AuthenticateInteractivelyAsync have to be called in a background service. The code I am looking to run could be run after the InteractiveService gets the access token, or triggered to run after the access token is recieved. I figured because of the samples that AuthenticateInteractivelyAsync had to be called in a background service.

Hi,

Does AuthenticateInteractivelyAsync have to be called in a background service.

Technically, no: the samples use a "background service" because it makes the Program.cs cleaner by separating the .NET generic host startup logic from the code that will process user input and render things in the console, but it's not mandatory (just recommended 😄).

If you don't use a BackgroundService and put your logic directly in Program, you'll need to tweak it to avoid using RunAsync(), as this method blocks until the host shuts down. Look for StartAsync() and StopAsync() as alternatives.

Hope it helped.