Events
Power BI DataViz World Championships
Feb 14, 4 PM - Mar 31, 4 PM
With 4 chances to enter, you could win a conference package and make it to the LIVE Grand Finale in Las Vegas
Learn moreThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
By Valeriy Novytskyy, Rick Anderson and Sharaf Abacery
This tutorial shows you how to enable users to sign in with their Google account using the ASP.NET Core project created on the previous page.
Follow the guidance in Integrating Google Sign-In into your web app (Google documentation)
Go to Google API & Services.
A Project must exist first, you may have to create one. Once a project is selected, enter the Dashboard.
In the Oauth consent screen of the Dashboard:
In the Credentials tab of the application Dashboard, select CREATE CREDENTIALS > OAuth client ID.
Select Application type > Web application, choose a name.
In the Authorized redirect URIs section, select ADD URI to set the redirect URI. Example redirect URI: https://localhost:{PORT}/signin-google
, where the {PORT}
placeholder is the app's port.
Select the CREATE button.
Save the Client ID and Client Secret for use in the app's configuration.
When deploying the site, either:
Store sensitive settings such as the Google client ID and secret values with Secret Manager. For this sample, use the following steps:
Initialize the project for secret storage per the instructions at Enable secret storage.
Store the sensitive settings in the local secret store with the secret keys Authentication:Google:ClientId
and Authentication:Google:ClientSecret
:
dotnet user-secrets set "Authentication:Google:ClientId" "<client-id>"
dotnet user-secrets set "Authentication:Google:ClientSecret" "<client-secret>"
The :
separator doesn't work with environment variable hierarchical keys on all platforms. For example, the :
separator is not supported by Bash. The double underscore, __
, is:
:
.You can manage your API credentials and usage in the API Console.
Google.Apis.Auth.AspNetCore3
NuGet package to the app.program.cs
:Add Authtication for asp.net app
The call to AddIdentity configures the default scheme settings. The AddAuthentication(IServiceCollection, String) overload sets the DefaultScheme property. The AddAuthentication(IServiceCollection, Action<AuthenticationOptions>) overload allows configuring authentication options, which can be used to set up default authentication schemes for different purposes. Subsequent calls to AddAuthentication
override previously configured AuthenticationOptions properties.
AuthenticationBuilder extension methods that register an authentication handler may only be called once per authentication scheme. Overloads exist that allow configuring the scheme properties, scheme name, and display name.
data-login_uri="{HostName}/{ControllerName}/{actionName}"
attrbute because after success login it will forward you to that link.string credential
, which is returned by Google upon completing the login process.credential
using the following line of code:
GoogleJsonWebSignature.Payload payload = await GoogleJsonWebSignature.ValidateAsync(credential);
The URI segment /signin-google
is set as the default callback of the Google authentication provider. You can change the default callback URI while configuring the Google authentication middleware via the inherited RemoteAuthenticationOptions.CallbackPath property of the GoogleOptions class.
services.AddIdentity
in ConfigureServices
, attempting to authenticate results in ArgumentException: The 'SignInScheme' option must be provided. The project template used in this tutorial ensures Identity is configured.ClientSecret
in the Google API Console.Authentication:Google:ClientId
and Authentication:Google:ClientSecret
as application settings in the Azure portal. The configuration system is set up to read keys from environment variables.ASP.NET Core feedback
ASP.NET Core is an open source project. Select a link to provide feedback:
Events
Power BI DataViz World Championships
Feb 14, 4 PM - Mar 31, 4 PM
With 4 chances to enter, you could win a conference package and make it to the LIVE Grand Finale in Las Vegas
Learn moreTraining
Module
Discover how Microsoft Entra External ID can provide secure, seamless sign-in experiences for your consumers and business customers. Explore tenant creation, app registration, flow customization, and account security.
Certification
Microsoft Certified: Identity and Access Administrator Associate - Certifications
Demonstrate the features of Microsoft Entra ID to modernize identity solutions, implement hybrid solutions, and implement identity governance.