[SOLVED] OAuth 2.0 and Google Signin in .NET 5 (core)?

Issue

I can’t find anything online that mimics Google sign-in for MVC 5 and below for implementation in MVC 6. Is it supported yet? I was using OWIN, but it appears that it is now obsolete in Core. Could anyone be so kind as to throw some links or info my way? I’m at a complete loss.

Solution

To setup Google Authentication in an ASP.net Core project do the following

  • Add the nuget package Microsoft.AspNet.Authentication.Google

I.e. add the following line to your project.json

"Microsoft.AspNet.Authentication.Google": "1.0.0-rc1-final"

Next, go to your startup.cs and add the following to your Configure method

        app.UseGoogleAuthentication(options =>
        {
            options.ClientId = "[YOUR APP CLIENT ID]";
            options.ClientSecret = "[YOUR APP SECRET]";
        });

NOTE – It is very important that you add the above code AFTER app.UseIdentity(); and BEFORE app.UseMVC()

For instructions on how to Obtain your ClientID / Secret from google go to the following site: https://developers.google.com/identity/sign-in/web/devconsole-project

I created a blog post detailing this out step by step
http://joeraio.com/using-google-authentication-with-asp-net-core-asp-net-5/

Answered By – Joe Raio

Answer Checked By – Katrina (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *