How to make OAuth2 work with an existing Asp.Net Identity user table?

Viewed 88

so, I just read up on and ultimately also implemented Google OAuth2 in my web application. I did it like this, roughly speaking

    services
        .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie(options =>
        {
            options.Events.OnRedirectToLogin = context =>
            {
                context.Response.StatusCode = 401;
                return Task.CompletedTask;
            };
        })
        .AddGoogle(options =>
        {
            options.ClientId = Configuration["GoogleClientId"];
            options.ClientSecret = Configuration["GoogleClientSecret"];
        });

My app already has an established Asp.Net Identity user entity, so there is an existing table of users who signed up on my page directly.

I'm now thinking about how I should connect OAuth users and this table. I have some questions on that end:

Maybe a first one off the bat, which does not entirely belong to the question, but still leaves me wondering:

The return url I use receives a claim cookie with some data like username, email etc. - According to some OAuth tutorials I read up on I thought that the my redirect url would receive an auth code I have to present to the google oauth server first? How do I have a cookie by this step already? Anyways - Now I have the users mail and name, and I technically have proof that the user is authenticated.

How would I now go ahead and map this to my existing table scheme? When signing up regular users, I would so far receive their email, username and password, and create a user for them. Would I now use the email and the name of the google claims, and create a "passwordless" login, which I would then login every time I receive a google login? In that case I can map the email to the user I added for the oauth user the first time he tried to access my app.

I'm also wondering whether OpenIDConnect would be something to use here. Still getting to grips with the terms, but it always sounds like this is the thing to use when I need authentication on top of regular OAuth.

I'm a bit confused, wondering if someone can give me some insights here.

0 Answers
Related