Good day, i´m a very beginning C# developer and trying to do my first steps with ASP.NET Core.
For now i´m at a point where i need some external help. I developed a Blazor based website and added some users to my database. Now i would like to add a function for loggedin users to change their password. My projekt is splitted to a serverside and a clientside. The clientside contains all my blazor/razor pages include the ChangePasswordView and the serverside receives the REST-requests from the client.
For authorisation i´m using the JWT (JSON WebToken) and i added this token with some claims to a local storage in browser.
The procedure is as following:
- User is logged in
- User inputs the old and the new password and hits a submit button
- The request function goes from the clientside to the serverside
- The POST-request gets to serverside UserController class which contains a "
ChangePassword(ChangePasswordModel pwModel)
" method. It receives the pwModel with the old and the new password successfully. - .... and now i have some problems.... I think i have to verify the JWTtoken from the local browserstorage or something like that, because the
_userManager.GetUserAsync(User)
always returns null.
How can help me to fix this issues to get a full functional "changePassword" method and what informations do you need?
Best regards, Larry
p.s. For sorry, this i my very first question on Stackoverflow and i tried to describe the issue as best as i can.
It seems a little, you forgot to implement some details. First of all, you need to add JWT authentication to your Startup.
ConfigureServices:
Configure:
The Controller method has to be decorated with the Authorize(AuthenticationSchemes = "Bearer") attribute
When you make a call to the controller, the HTTP request must have the Authorization header.