fullstackhero / dotnet-starter-kit

Production Grade Cloud-Ready .NET 8 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.
https://fullstackhero.net/dotnet-webapi-boilerplate/
MIT License
5.28k stars 1.58k forks source link

JwtAuthenticationService #1014

Closed commodus closed 2 months ago

commodus commented 2 months ago

Hi @iammukeshm,

I am getting an error with no details in the JwtAuthenticationService.cs file line 57 I am using SqlServer database. This error occured when getting your latest commit.
image

image

Thank you

iammukeshm commented 2 months ago

@commodus is there any error log on the browser console?

iammukeshm commented 2 months ago

@commodus I dont seem to have this issue. It logs in fine for me. PS i am using PostgreSQL. I would need more info to figure out the issue

commodus commented 2 months ago

Hello @iammukeshm, Thanks for your quick response. When I set the "launchBrowser" value to false in the launchSettings.json file and run the Blazor application on port 7100, I don't encounter this error. However, when I set the "launchBrowser" value to false on port 55951 and fill in the administrator settings and click the Sign In button, it gives me this error. I can catch this code block within a try-catch. Below, I am sharing the screenshot and stack trace.

image

' at System.Net.Http.BrowserHttpInterop.d131[[System.Runtime.InteropServices.JavaScript.JSObject, System.Runtime.InteropServices.JavaScript, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()\n at System.Net.Http.BrowserHttpHandler.CallFetch(HttpRequestMessage request, CancellationToken cancellationToken, Nullable1 allowAutoRedirect)\n at System.Net.Http.BrowserHttpHandler.gImpl|53_0(HttpRequestMessage request, CancellationToken…pi.ApiClient.TokenGenerationEndpointAsync(String tenant, TokenGenerationCommand body, CancellationToken cancellationToken) in C:\Users\xxx\source\repos\dotnet-starter-kit\src\apps\blazor\infrastructure\Api\ApiClient.cs:line 3188\n at FSH.Starter.Blazor.Infrastructure.Auth.Jwt.JwtAuthenticationService.LoginAsync(String tenantId, TokenGenerationCommand request) in C:\Users\xxx\source\repos\dotnet-starter-kit\src\apps\blazor\infrastructure\Auth\Jwt\JwtAuthenticationService.cs:line 59'

iammukeshm commented 2 months ago

@commodus I suspect this might be the CORS issue. It should be logged on your browser console i believe. So if you run your blazor application on , let's say port https://localhost:1234, you need to make sure to add this address to the API's app settings.

Specifically in this list,

"CorsOptions": {
  "AllowedOrigins": [
    "https://localhost:7100",
    "http://localhost:7100",
    "http://localhost:5010"
  ]
},

Only the requests coming from the addresses mentioned in this list will be allowed by the API. it will block requests from any other URLs. Let me know if this helps

commodus commented 2 months ago

Thank you. I will try it.