Skip to main content
Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Languages
    • Angular Angular js ASP.NET Asp.net Core ASP.NET Core, C# ASP.NET MVC ASP.NET Web Forms C C# C#, ASP.NET Core, Dapper
      C#, ASP.NET Core, Dapper, Entity Framework DotNet General Web Development HTML, CSS HTML/CSS Java JavaScript JavaScript, HTML, CSS JavaScript, Node.js Node.js
      Python Python 3.11, Pandas, SQL Python 3.11, SQL Python 3.11, SQLAlchemy Python 3.11, SQLAlchemy, SQL Python 3.11, SQLite React Security SQL Server TypeScript
  • Post Blog
  • Tools
    • Beautifiers
      JSON Beautifier HTML Beautifier XML Beautifier CSS Beautifier JS Beautifier SQL Formatter
      Dev Utilities
      JWT Decoder Regex Tester Diff Checker Cron Explainer String Escape Hash Generator Password Generator
      Converters
      Base64 Encode/Decode URL Encoder/Decoder JSON to CSV CSV to JSON JSON to TypeScript Markdown to HTML Number Base Converter Timestamp Converter Case Converter
      Generators
      UUID / GUID Generator Lorem Ipsum QR Code Generator Meta Tag Generator
      Image Tools
      Image Converter Image Resizer Image Compressor Image to Base64 PNG to ICO Background Remover Color Picker
      Text & Content
      Word Counter PDF Editor
      SEO & Web
      SEO Analyzer URL Checker World Clock
  1. Home
  2. Blog
  3. ASP.NET MVC
  4. Google Sign In using GoogleAuthentication Nuget package in Asp.Net MVC

Google Sign In using GoogleAuthentication Nuget package in Asp.Net MVC

Date- Mar 12,2022 Updated Jan 2026 10109 Pay & Download
Google Sign In Google Login

GoogleAuthentication Nuget Package

GoogleAuthentication  package can be install from Nuget packages and it is supported in .Net MVC and .net Core. It helps you to integrate google signin in three easy steps and you will be able to check the data retunred from google.For installing this you have to follow the steps

Google Sign In using GoogleAuthentication Nuget package in AspNet MVC

You can also install this nuget package using the command in package manager console 

Install-Package GoogleAuthentication -Version 1.0.0

After you have successfully installed GoogleAuthentication pakage . You have to go to the controller and add this namespace on your controller.

Google Sign In using GoogleAuthentication Nuget package in AspNet MVC 2



using GoogleAuthentication.Services;

Now, we will see how to use that in the code to get GoogleLogin working.


  public ActionResult Index()
        {
            var ClientID = "Enter client id here";
            var url = "https://localhost:44375/Login/GoogleLoginCallback";
            var response = GoogleAuth.GetAuthUrl(ClientID, url);
            ViewBag.response = response;
            return View();
        }

So , this will be the action which will be called for showing the Google Sign In button. Here , we need to pass the Client Id and redirect url to our function and it will return us a Url which we have to pass in the href of Login anchor tag as discussed in next step. For getting the Client Id and setting Redirect Url you can check out detailed steps in How to get Client Id and register Redirect Url . 

 var response = GoogleAuth.GetAuthUrl(ClientID, url);
 ViewBag.response = response;

Here, we are passing client id and url to GetAuthUrl and this will return url which we setting in ViewBag and will be used in next step. Now on the view you have to add one button like this


<a class="btn btn-default" href="@ViewBag.response">Goggle Log in</a>

Now we have to creating a new action method to catch the redirect url and must match the name of the redirect url action. So we will add this new action

  public async Task<ActionResult> GoogleLoginCallback(string code)
        {
            try
            {
                var ClientSecret = "Enter Client Secret here";
                var ClientID = "Enter Client Id here";
                var url = "https://localhost:44375/Login/GoogleLoginCallback";
                var token = await GoogleAuth.GetAuthAccessToken(code, ClientID, ClientSecret, url);
                var userProfile = await GoogleAuth.GetProfileResponseAsync(token.AccessToken.ToString());
                var googleUser = JsonConvert.DeserializeObject<GoogleProfile>(userProfile);
               
            }
            catch (Exception ex)
            {
                
            }
            return RedirectToAction("index", "Users");
        }

Code- This will be the parameter that we received from google containing a code that is used to obtain token in next steps.

ClientId- This must be the Client Id which we have used in first step

ClientSecret- ClientSecret can be obtained from the same place from where you get the ClientId.

Url- This is the same redirect url that we have used in first step.

var token = await GoogleAuth.GetAuthAccessToken(code, ClientID, ClientSecret, url);

This method will take the parameters explained above and will return you a access token which we be used in next step to obtain profile info.

  var userProfile = await GoogleAuth.GetProfileResponseAsync(token.AccessToken.ToString());

This method will take the access token from previous method and return back the profile data for the user that we have logged in . This will be in json format. You can check the returned data format in next imageGoogle Sign In using GoogleAuthentication Nuget package in AspNet MVC 3

For searializing this json , you can create this class model.

 public class GoogleProfile
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Picture { get; set; }
        public string Email { get; set; }
        public string Verified_Email { get; set; }
        public string MobilePhone { get; set; }
        public string Locale { get; set; }
    }

Now , you can deseiralize the json data using our model And then use the data anywhere you need.

 var googleUser = JsonConvert.DeserializeObject<GoogleProfile>(userProfile);

This is how we can  integrate Google Sign In using GoogleAuthentication Nuget package in Asp.Net MVC  using some easy steps. If you face any issue don't forget to add comments .

S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Integrating Google Sign in Asp.net MVC
Jan 22, 2022
How to Integrate Google Sign in Asp.net Core 8.0
May 05, 2024
Linkedin Sign In using LinkedinLogin Nuget package in Asp-Net MVC
Apr 14, 2023
Linkedin Sign In using LinkedinLogin Nuget package in Asp-Net MVC
Jul 05, 2022
Previous in ASP.NET MVC
Integrating Google Sign in Asp.net MVC
Next in ASP.NET MVC
How to Auto Redirect from HTTP To HTTPS IN Asp.Net using Web Con…
Buy me a pizza

Comments

On this page

🎯

Interview Prep

Ace your ASP.NET MVC interview with curated Q&As for all levels.

View ASP.NET MVC Interview Q&As

More in ASP.NET MVC

  • Implement Stripe Payment Gateway In ASP.NET 58730 views
  • Jquery Full Calender Integrated With ASP.NET 39646 views
  • Microsoft Outlook Add Appointment and Get Appointment using … 27569 views
  • How to implement JWT Token Authentication and Validate JWT T… 25258 views
  • Payumoney Integration With Asp.Net MVC 23219 views
View all ASP.NET MVC posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • SQL Formatter
  • Diff Checker
  • Regex Tester
  • Markdown to HTML
  • Word Counter
More Tools
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Base64 Encoder
  • JWT Decoder
  • UUID Generator
  • Image Converter
  • PNG to ICO
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • ASP.NET
  • Asp.net Core
  • ASP.NET Core, C#
  • ASP.NET MVC
  • ASP.NET Web Forms
  • C
  • C#
  • C#, ASP.NET Core, Dapper
  • C#, ASP.NET Core, Dapper, Entity Framework
  • DotNet
  • General Web Development
  • HTML, CSS
  • HTML/CSS
  • Java
  • JavaScript
  • JavaScript, HTML, CSS
  • JavaScript, Node.js
  • Node.js
  • Python
  • Python 3.11, Pandas, SQL
  • Python 3.11, SQL
  • Python 3.11, SQLAlchemy
  • Python 3.11, SQLAlchemy, SQL
  • Python 3.11, SQLite
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor