Securing .Net 10 WebApi to be called by Windows Application

Kmcnet 1,421 Reputation points
2026-07-18T01:48:31.2233333+00:00

Hello everyone and thanks for the help in advance. I am developing a .Net 10 WebApi that will be called by a Windows application. When searching for solutions I am confused if the calling application changes how the api is secured. Any help would be appreciated.

Developer technologies | .NET | Other

2 answers

Sort by: Most helpful
  1. Danny Nguyen (WICLOUD CORPORATION) 8,015 Reputation points Microsoft External Staff Moderator
    2026-08-07T03:28:39.0966667+00:00

    Hi @Kmcnet ,

    There's one small misunderstanding worth clearing up:

    the api accepts the JWT, contacts the issuer and validates this request

    The API does not contact the issuer on every request. A JWT is self-verifying: the issuer signs it, and the API verifies that signature locally using the shared secret (symmetric) or the issuer's public key (asymmetric). If the signature checks out, the API knows the token wasn't tampered with and came from the matching key.

    With asymmetric keys the API does fetch the issuer's public keys once from its discovery endpoint (.well-known/openid-configuration) and caches them — but that's a one-time fetch, not a per-request round trip. That's why JWTs are fast and scalable.

    Wouldn't I just generate a hard coded symmetric key then validate it?

    Technically yes, that's exactly how the sample code works — the client signs with a symmetric key, the API validates with the same key, no third party involved. It's fine for local testing and for server-to-server calls where both ends are back-end servers you control.

    But it breaks down for a Windows desktop app. A desktop app is a public client — it runs on the user's machine and can be decompiled. Anyone who extracts that symmetric key can mint their own tokens and impersonate any user, indefinitely. The deciding factor isn't how many apps you have; it's who can get at the key.

    That's what an identity provider solves: the signing key stays on a locked-down server, the app just asks for a token and passes it to your API.

    1. Windows app asks the identity provider to authenticate the user
    2. Identity provider (holding the private key on its own servers) mints the token
    3. Windows app sends that token to your API

    So even with one app and one API, a desktop client still needs a provider — Entra, Auth0, Keycloak, or your own via OpenIddict / ASP.NET Core Identity.

    Was this answer helpful?


  2. AgaveJoe 31,376 Reputation points
    2026-07-29T18:51:20.8666667+00:00

    Thanks for the follow-up and my apologies as I have been reading up on oauth. While I realize rolling my own is more difficult, it helps me learn when I implement libraries. I am still confused on the workflow. Once the jwttoken and passed to the secure endpoint, what does the endpoint need to do to validate the token. And does each call to the endpoint by the consuming application require authentication?

    Kmcnet, the short answer is "it depends" on how the token is constructed by your identity provider. However, the standard mechanics break down into a few key areas:

    Token Validation (Cryptography):

    If you are using a library like OpenIddict, tokens can sometimes be formatted as encrypted reference tokens or opaque tokens, meaning the API needs the decryption key to read them.

    More commonly with standard JWTs, the token is digitally signed using a private key by the authorization server. To validate it, your Web API needs the corresponding public key (usually fetched automatically via standard discovery endpoints like .well-known/openid-configuration) to verify the signature and ensure it hasn't been tampered with.

    Per-Call Authentication:

    Yes, conceptually, every single call to a secure endpoint requires the client to present credentials (the JWT Bearer token) in the HTTP Authorization header (Authorization: Bearer <token>).

    However, from a performance standpoint, the API doesn't make a network call back to the auth server on every single request to validate it. Instead, once the API has the public key, it cryptographically validates the token locally, checks the expiration (exp), issuer (iss), and audience (aud) claims in memory.

    Scopes and Grants:

    Once the signature is verified, the API checks the claims inside the token—specifically scopes and roles—to determine if that specific client and user are authorized to access that particular endpoint (Authorization vs. Authentication).

    This is essentially the core of what you'll be digging into as you research OAuth and token-based architecture. Looking into how ASP.NET Core handles the JwtBearer authentication handler will give you a good blueprint for how validation happens under the hood.

    https://learn.microsoft.com/en-us/aspnet/core/security/authentication/configure-jwt-bearer-authentication?view=aspnetcore-10.0

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.