Skip to content
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

Development feature - User Management #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mikkelly-mi
Copy link

πŸ’» Change Type

  • ✨ Code
  • πŸ§ͺ Tests
  • ♻️ refactor
  • 🩹 Bugfix
  • βš™οΈ Setup
  • πŸ”¨ Chore
  • πŸ”„ Merge
  • πŸ“ Docs

πŸ”€ Description

Feature - User Management (for current user application)

  • The main endpoint group is"user" added: register, login, profile.
  • Added authentication, based on JWT.
  • Added Identity seeder for MongoDB.

πŸ”„ Changes

πŸ–ΌοΈ Screenshots (optional)

(If applicable, add screenshots or other visual information that helps to understand the changes.)

πŸ“ Additional Notes

(Anything else you'd like to add that might be relevant for the review or implementation.)

…s "user" add: register, login, profile. Added authentication, based on JWT. Added Identity seeder for MongoDB.
@ktutak1337
Copy link
Owner

Thank you very much for your pull request and for taking the time to contribute to the project!

I noticed that you've added the AspNetCore.Identity.MongoDbCore NuGet package. Could you please clarify if this library is essential for the feature we're implementing? The last release of this library was in 2021, and it seems that it might no longer be actively maintained. This raises some concerns, especially when dealing with security features like authentication and authorization.

Given the importance of security in our project, I'd like to suggest taking a look at a previous project of mine where I implemented a similar feature without relying on third-party libraries. I focused on using the built-in .NET APIs to handle authentication. You can find the implementation here .

Additionally, the codebase already includes an existing implementation of the IContext interface within the Shared project. This interface provides access to request information and the authenticated user. It might be more consistent to use this rather than the IHttpContextAccessor.

Finally, I think it would be great if we could also implement a few additional features, either in this PR or through separate issues/PRs:

  • An endpoint for refreshing and revoking access tokens.
  • Storing access tokens using caching mechanisms, such as IMemoryCache, which is already available in the .NET API.
  • Storing JWT tokens in cookies, which can be returned by the authentication endpoint.

I’ve also left a few comments directly within the code for further feedback. If you have any questions or need further clarification, please feel free to reach out!

Thanks again for your work on this! Looking forward to your thoughts.


internal class GetProfileHandler : ICommandHandler<GetProfile, GetProfileResponse>
{
private readonly IHttpContextAccessor _httpContextAccessor;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using IContext interface from the Shared project instead of IHttpContextAccessor. IContext is already designed to handle request information and the authenticated user, so it might be a more consistent approach across the codebase.

MongoDbSettings = new MongoDbSettings
{
ConnectionString = options.CONNECTION_STRING,
DatabaseName = "StellarChat"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid hardcoding values directly in the code. Instead, consider using constant variables or values from appsettings.json. For example, the database name can be retrieved from the mongo:database setting in appsettings.json. This approach will make the code more maintainable and configurable.

await _userManager.AccessFailedAsync(user);

if (await _userManager.IsLockedOutAsync(user))
return new LoginUserResponse(false, "Your account is locked out. Please try again later.", null);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning a record for error handling, consider using custom exceptions. This approach will help to standardize error handling across the application and make it easier to manage and trace exceptions.

@mikkelly-mi
Copy link
Author

@ktutak1337 ,

I completely agree with all your suggestions. Often the fastest solution is not the best. I hope I will soon find time to make this functionality the right way. Thank you for your cooperation! See you soon, with a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants