"
 
 
 
ASP.NET (snapshot 2017) Microsoft documentation and samples

Configuring Google authentication in ASP.NET Core

By Valeriy Novytskyy and Rick Anderson

This tutorial shows you how to enable your users to sign in with their Google+ account using a sample ASP.NET Core 2.0 project created on the previous page. We start by following the official steps to create a new app in Google API Console.

Create the app in Google API Console

Google API Console
Google API Console
API Manager Library page
API Manager Library page
New Project dialog
New Project dialog
API Manager Library page
API Manager Library page
API Manager Google+API page
API Manager Google+API page
API Manager Google+API page
API Manager Google+API page
API Manager Credentials page: Find out what kind of credentials you need panel
API Manager Credentials page: Find out what kind of credentials you need panel
API Manager Credentials page: Create an OAuth 2.0 client ID
API Manager Credentials page: Create an OAuth 2.0 client ID
API Manager Credentials page: Set up the OAuth 2.0 consent screen
API Manager Credentials page: Set up the OAuth 2.0 consent screen
API Manager Credentials page: Download credentials
API Manager Credentials page: Download credentials

Store Google ClientID and ClientSecret

Link sensitive settings like Google Client ID and Client Secret to your application configuration using the Secret Manager. For the purposes of this tutorial, name the tokens Authentication:Google:ClientId and Authentication:Google:ClientSecret.

The values for these tokens can be found in the JSON file downloaded in the previous step under web.client_id and web.client_secret.

Configure Google Authentication

ASP.NET Core 2.x

Add the Google service in the ConfigureServices method in Startup.cs file:

[!INCLUDEdefault settings configuration]

ASP.NET Core 1.x

The project template used in this tutorial ensures that Microsoft.AspNetCore.Authentication.Google package is installed.

Add the Google middleware in the Configure method in Startup.cs file:


See the GoogleOptions API reference for more information on configuration options supported by Google authentication. This can be used to request different information about the user.

Sign in with Google

Run your application and click Log in. An option to sign in with Google appears:

Web application running in Microsoft Edge: User not authenticated
Web application running in Microsoft Edge: User not authenticated

When you click on Google, you are redirected to Google for authentication:

Google authentication dialog
Google authentication dialog

After entering your Google credentials, then you are redirected back to the web site where you can set your email.

You are now logged in using your Google credentials:

Web application running in Microsoft Edge: User authenticated
Web application running in Microsoft Edge: User authenticated

Troubleshooting

Next steps





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnetcore/security/authentication/social/google-logins.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>