Google external login setup in ASP.So I started a sync with google drive and set it to drive.file scope. So you can use this code to adapt it to other languages like ASP.NET C#. In chapter 2.2 you will find an example code written in PHP with no external packages required and no framework needed. More about the Microsoft SQL Server LocalDB you can read in my following post Ĭlick on the link Click here to confirm your accountįinally we signed-in to our web application with the Google account.Ĭreate a web app without using any external packages or frameworksĪ great resource about OAuth 2.0 you will find in the following link In this table the email will be used also as username. The user is created in the database table dbo.AspNetUsers and dbo.AspNetUserLogins, after you click the register button below. So this process and page below will only appear for the first user registration. ![]() Finally you had to refresh the page after the migration is applied.īehind the scenes our web application will create a Microsoft SQL Server LocalDB database to store the users in. The following screen only appears the first time and has nothing to do with the actual sign-in process with Google.Ĭlick on Apply Migrations below and follow the instructions. Here you can see the sign-in page from Google with our previously configured OAuth consent screen and credentials for the web application type. Now we can test if it works and can hit the F5 button to start debugging.Īs we want to authenticate and sign-in with our Google account, I will click on the Google button. Options.ClientSecret = googleAuthNSection IConfigurationSection googleAuthNSection =Ĭonfiguration.GetSection("Authentication:Google") Now after configuring the the Google client ID and secret we need to configure the Google authentication in our Startup.cs file and there we need to add the following code into the public void ConfigureServices method: services.AddAuthentication() You can list all the secrets for your ASP.NET Core project from the command line to view the secret API key. To add our secret from Google we have to add the following secretsĭotnet user-secrets set “Authentication:Google:ClientId” “”ĭotnet user-secrets set “Authentication:Google:ClientSecret” “” Once you have enabled secrets for your ASP.NET Core project, you can set and list secrets from the command line as well. This directory contains a secrets.json file that will be used to store your secrets. It also adds a directory with the same name as your UserSecretsId on your development PC. The inner text is arbitrary, but is unique to the project. ![]() By default, the inner text of UserSecretsId is a GUID. The preceding command adds a UserSecretsId element within a PropertyGroup of the project file. You have to execute this command in the project file folder. Safe storage of app secrets in development in ASP.NET CoreĪSP.NET Core User Secrets and Secret Manager Tool The following articles are about how to store secret data in your web app but is not the topic of my post. I will using the ASP.NET Core Web App (Model-View-Controller) template for this test.įor Authentication Type select Individual Accounts Google external login setup in ASP.NET Core Here we need to add the URL from our Web App and the callback path under redirect URI to which the authorization code is send.Ĭreate an ASP.NET Core Web App to authenticate against Google using OAuth 2.0įor configuring the ASP.NET Core Web App I used the following well documented articles from Microsoft.įacebook, Google, and external provider authentication in ASP.NET Core Now after finishing the consent screen configuration I came back to the point to create the credentials with OAuth client ID.įor the Application type select Web application. While publishing status is set to Testing, only test users are able to access the app. The access token which is issued to the user is limited to those defined scopes. ![]() If the application the first time wants to access these scopes, the user will see a consent screen where he must consent in order to allow the application to access its account data. You can define one or more scopes which an application can request for. I will add here the /auth/userinfo.email and openid scope.Ī Scope limits the access of an application to a user’s account. You will also need to provide a developer contact email address. In order to create an OAuth client id, I will first need to configure the consent screen.įor testing purpose I will use the localhost App URL from the Visual Studio Debugging URL. In order to I also need to create a new Project. Here first I need to create Credentials for the OAuth 2.0 Client IDs API. Login Google Cloud Platform (API & Services) I will first need to login into the Google Cloud Platform and APIs & Services using the following link. Because of this I was set up an ASP.NET Core Web App to test Google’s OAuth 2.0 API.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |