Hi,
I am migrating my user management system, from my own JWT-based, to Auth0.
For simple example, lets say that i have/had two tables:
- Posts, with columns: “Content”, “Date”, “Username”
- Users, with columns: “ID”, “Username”, “PassHash”, “PassSalt”
For now, every post entry in database, has Username field, in which i was storing username of user which created this post. I was obtaining that username, based on my own JWT Cookie, with some Claims.
So, i have got two questions:
- How can i now save some user id/username/anything that can point to specific user at Posts table? What should i use? Of course i don’t mean asking You about usage of Entity Framework, but asking about what value i am looking for, and how to get that value after successful user login
- If i want to get usernames for all of stored userids, what is the best/most effective way to do that? For example i will need to show a lists of users posts in a table, and there will be “user name” column, in which i will need to show user names of specific post. How to make it in a best possible way?
- How can i maintain cookies? Do i need to maintain them? For now i have copied a lot from Auth0 .net core mvc quickstart guide, and everything is working, but while this code:
public IActionResult Profile()
{
return View(new UserProfileViewModel()
{
Name = User.Identity.Name,
EmailAddress = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value,
ProfileImage = User.Claims.FirstOrDefault(c => c.Type == "picture")?.Value
});
}
is indeed working, when i’m trying to get all of these values inside other razor page, for example with:
User.FindFirst(ClaimTypes.Name)?.Value
I am always getting null. What am i doing wrong?
Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuth0WebAppAuthentication(options =>
{
options.Domain = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";
options.ClientId = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";
});
builder.Services.Configure<CookiePolicyOptions>(options =>
{
options.MinimumSameSitePolicy = SameSiteMode.None;
});
(...)
Do i need to implement some middleware, to keep data recieved from Auth0 after login into some cookie?
Thanks in advance!