-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After implementing jwt I always got HttpContext.User is null #1031
Comments
Check values of claim constants. |
Hello @salmanshafiq00, your solution looks promising, and I'd like to investigate the null issue you encountered. Could you please push your implementation to the repository so that I can clone it and examine the code more closely? This will help me better understand the problem and assist with finding a resolution. Thank you! |
@salmanshafiq00 I've been wrestling with similar in an effort to implement a more 'vanilla' JWT and I believe it's because the system isn't recognising your DefaultAuthenticationScheme and because of it, is not calling the [Authorize] attribute in the way you'd expect. I believe you can decorate controllers with: [Authorize(AuthenticationSchemes = "Bearer")] I had thought I had set the authentication scheme in the way I set up identity but it doesn't seem to translate. I'll add more when/if |
@iamcymentho @Chris-Mingay , |
Describe the bug
I clone .net 7.0 project and implement jwt on this project. Also I used MS default Web API project instead SPA. After successful login and I tried to get data from another action which has authorize attribute. But unfortunately, I always found unauthorized even though it authorized request.
Here is my jwt provider class which in infrastructure layer.
public async Task GenerateJwtAsync(string userId)
{
var user = await _userManager.FindByIdAsync(userId);
}
Here, is the dependency register in DependencyInjection classs.
Unfortunately, I got null from HttpContext's User.
Here, is my CurrentUser service for getting the current user
I tried a lot can't find any solutions. I have nothing what should to do. pls help.
The text was updated successfully, but these errors were encountered: