✅ help me understand
I want to create a web api forum pet project, but only using google oauth for auth. I implemented the process of getting the access token from google, but i don't know how do i need to store user in db, so i can get all posts, info about user that wrote this post (like his pfp etc)
10 Replies
Are you using Identity, or do you want to write the auth from scratch?
Whatever makes me use user.claims and authorize attribute
I really have both implemented and dont know which one is better
Identity, then
If you hooked up Google OAuth to Identity properly, then you can just use Identity as usual
Assuming your
DbContext
inherits IdentityDbContext
you can create a navigation property to IdentityUser
in any other EF entity
And query like thatI connected google ouath through Authentication.Google package with AddAuthenticatio().AddGoogle method
It should just work, then
Does it create user automatically in db?
When the user registers, yes
Or, I guess in case of OAuth, when they log in for the first time
Check the database and see if the user has been created
If user changes google username, does it update the db next time he logins?
Or pfp, etc
IIRC what gets saved in the database is just the user identifier of some sort
And all the data from their Google account are saved in the claims
Each time on login
Don't quote me on that, though
Thx