Follow these SIMPLE instructions to Authenticate your new dotnet5 MVC app with Google (the EASY way) :
Note: you might need to install the dotnet framework toolset first, and the dotnet framework development toolkit. I recommend the windows terminal which is basically powershell with a package manager inside of it.
And if you prefer to watch it in a video I made one of those as well here:
first go here and create your credentials...: https://console.developers.google.com/apis/credentials
then commandline time:
dotnet new mvc -o MyApplicationName --auth Individual
dotnet add package Microsoft.AspNetCore.Authentication.Google
dotnet user-secrets init
dotnet user-secrets set "Authentication:Google:ClientId" <MyClientIDSecret>
dotnet user-secrets set "Authentication:Google:ClientSecret" <MyClientSecret>
dotnet add package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.AspNetCore.Identity.UI
dotnet tool update --global dotnet-ef
dotnet ef migrations add InitialCreate
dotnet ef database update
then open in visual studio or vs code and change the code:
just above addControllersWithViews:
services.AddAuthentication()
.AddGoogle(options =>
{
IConfigurationSection googleAuthNSection =
Configuration.GetSection("Authentication:Google");
options.ClientId = googleAuthNSection["ClientId"];
options.ClientSecret = googleAuthNSection["ClientSecret"];
});
add [Authorize] to home controller
add [Allowanonymous] to index
If you liked this video, be sure to bookmark my blog, and subscribe to my YouTube channel -> as of today (january 2021) I do more on YouTube than in blogs, but that is subject to change.
No comments:
Post a Comment