Search code examples
c#jwtblazoridentityserver4openid-connect

Blazor Wasm Authorization state logged multiple times


I'm currently working on a Blazor Webassembly application consuming data from an API. Both applications are secured by an IdentityProvider (IdentityServer4):

  • Blazor Wasm App (Oidc)
  • API
  • IdentityServer4

It works fine, I can login, logout and retrieve the correct data.

I'm running into 1 issue though:

info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[1]
      Authorization was successful.

This message is logged multiple times from blazor.webassembly.js:1, basically any time I do a page transition or load data on a grid or actually any other possible activity.

It looks to me like a permanent roundtrip from the Blazor app back to the IdentityServer4.

Do you know why this log message appears multiple times?

How can I solve this issue?


Solution

  • How can I solve this issue?

    By ignoring it. No issue here.

    It looks to me like a permanent roundtrip from the Blazor app back to the IdentityServer4

    Not at all. A message such as this:

    info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[1] Authorization was successful.

    is issued by the authorization service when you try to access a protected resource ( annotated by the Authorize attribute), and it is called to check if you are authorized to access the protected resource. In your Blazor client, annotate the Counter page with the Authorize attribute, run your app, and alternately navigate from the Index page to the Counter page (after being authenticated), you'll notice that each time you try to navigate to the Counter page the above message will increase by one (to left of the message). Once again, this is because the authorization service is being called to check if you are authorized to access the protected resource... This is by design. You authenticate only once, but being spied on again and again, not without reason of course, and even that not always succeed.