How to Add Google Authentication into a ASP.NET Core Application

Поділитися
Вставка
  • Опубліковано 29 січ 2025

КОМЕНТАРІ • 148

  • @RoundTheCode
    @RoundTheCode  4 роки тому +7

    Thinking of doing a full course on Google Authentication in ASP.NET Core. Let us know which areas you would like to be covered.

    • @muraterkan3251
      @muraterkan3251 9 місяців тому

      Bro it ferfect but mor than perfect. please explain bigger size. Your screen resulation so b big.

  • @ilyachudinovskikh571
    @ilyachudinovskikh571 3 роки тому +1

    I dont often write comments on youtube, but you did a great job and that is the best youtube guide for this kind of stuff. Thanks a lot and shoutout from Russia!)

  • @nontin21
    @nontin21 2 роки тому +2

    Hello, thanks for the guide. everything works fine when i run the app in local.
    so after i published it and i test it online, the google auth opens, but it never hits my controller, i get an error. do you have any idea why? do i have to publish the App in google.console to make it run in my live website? Google login works local, but doesn't work live.
    for example: domain/signin-google returns error 500 for the live website, but localhost:port/signin-google hits my ExternalLogin Controller.

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      Have you added your live domain as an "Authorised Redirect URI"?

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      So you should create a new "Authorised Redirect URI" of {livedomain}/signin-google.

    • @nontin21
      @nontin21 2 роки тому

      @@RoundTheCode yes i have. I get redirected to aoth page i select my gmail account from the list then i get error 500 and it never hits my controller to receive the login info. Local it works

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      @@nontin21 And I'm assuming your live domain is on HTTPS? You probably need to get the inner exception of the 500 error to diagnose it further. If you're not sure how to do that in a production environment, you can follow this tutorial that allows you to write errors to a text file:
      ua-cam.com/video/I3tlCn5J9pA/v-deo.html

    • @renjuag8279
      @renjuag8279 9 місяців тому

      Please provide solution on this, Getting the same 500 error in production

  • @donaldlee6760
    @donaldlee6760 4 роки тому +2

    Very nice explanation - thank you. I successfully added Google authentication to my asp.net core 3.1 app using your video. Next step is to add a logout button.

    • @RoundTheCode
      @RoundTheCode  4 роки тому

      That's good to hear. It's good that ASP.NET Core has it's own NuGet packages for authentication.

    • @chandankarmakar6651
      @chandankarmakar6651 4 роки тому

      Hi, can you tell us how to add a logout button?

    • @iyashasgowda
      @iyashasgowda 4 роки тому

      @@chandankarmakar6651 Steps for logging out :
      1. Redirect the user to the login page.
      2. Clear the saved cookie on logout button clicked.

  • @aniljain50
    @aniljain50 4 роки тому +4

    Excellent tutorial and very simple!!

  • @sanjayprajapati3540
    @sanjayprajapati3540 3 роки тому +1

    This is what i was actually looking for , thanks

    • @RoundTheCode
      @RoundTheCode  3 роки тому +1

      Thanks for your comment, Sanjay.

  • @fredrickamoako
    @fredrickamoako Рік тому

    I cannot see how and why clicking on privacy link would direct a user to the google signin page, how it was setup to provide that functionality currently boggles my mind. Can you provide a clear explanation as to how it's setup to function that way? I have carefully gone through the code shared on the github repo and I can't see anything but it works fine.

    • @RoundTheCode
      @RoundTheCode  Рік тому

      The HomeController is fixed with the [Authorize] attribute. Therefore any action within that controller requires authentication before being authorised to view the page.
      The Index page doesn't require it as it has the [AllowAnonymous] attribute assigned to it. Action attributes take more priority than controller attributes.
      In Startup.cs, we have configured authentication to go through Google. This uses functionality in the Microsoft.AspNetCore.Authentication.Google NuGet package to handle authentication when it's required.

  • @HaoNguyen-km9xj
    @HaoNguyen-km9xj 3 роки тому

    Is the .net web API can do like that.....I have a mobile app with flutter, the backend is .net 5 web API and in flutter I have implement google sign in with firebase , how can I implement the API match with flutter,...

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      Hi Hao. Not sure to be honest. Never had any experience with Flutter.

  • @mdakatt
    @mdakatt 2 роки тому +1

    Thanks a lot, its works you saved me hours to deal with Authentication roles and databases n just use this service ♥that

  • @mrohailiqbal
    @mrohailiqbal 3 роки тому +1

    Very informative. Keep up the good work bro :)

  • @gorkemgenarakkaya4570
    @gorkemgenarakkaya4570 3 роки тому

    I encounter cors error when i run the project with angular although added the cors policy. Do you know how to fix?

    • @RoundTheCode
      @RoundTheCode  3 роки тому +1

      Hi Görkem,
      The CORS policy is the fix! So it's probably your implementation that isn't quite right. Make sure that the host of your Angular application is inside the CORS middleware in your API.
      Check out our article for more information.
      www.roundthecode.com/dotnet/getting-started-with-cors-in-asp-net-core

    • @gorkemgenarakkaya4570
      @gorkemgenarakkaya4570 3 роки тому

      @@RoundTheCode Ok thank you so much for support. Im gonna check this out

    • @jose.salgado
      @jose.salgado 2 роки тому

      Hi! I'm getting also a CORS issue using react. It seems be on the redirect: Access to XMLHttpRequest at 'accounts.google.com/o/oauth2/v2/auth?etc') from origin 'localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Do you have any idea what could be?

  • @amalchacko8784
    @amalchacko8784 2 роки тому +1

    Thanks for the tutorial

  • @Thephoenix777
    @Thephoenix777 4 роки тому

    I don't have the fields you have, when i go to select internal vs external it talks about test users, not "everyone" I don't want to specify test users. Please ensure to elaborate on that.

    • @RoundTheCode
      @RoundTheCode  4 роки тому

      Not sure if I follow what you are saying?

    • @SvenLowry
      @SvenLowry 4 роки тому

      @@RoundTheCode The "Internal / External" users choice when managing consent has changed now. The External option wording now mentions that to start with, your app is in "test" mode and will only allow whitelisted test accounts to login until you publish it.

  • @ranjitumakanthan994
    @ranjitumakanthan994 3 роки тому +1

    I tried and its working, Thank you for the detailing explanations

  • @MateriaMaster6
    @MateriaMaster6 3 роки тому +2

    You're so awesome, you really know your stuff, great content :)

  • @aminarifovic8028
    @aminarifovic8028 2 роки тому

    First of all thank you for the great guide but just one question. How do you let others access the google login from different systems.

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      With your Google project, you'd have to set up a separate sign in URL for each system I believe.

  • @elija.
    @elija. 3 роки тому

    what about getting the code to create access token?

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      I will have to look into that. But you can probably stick a breakpoint on the "result" variable in AccountController > GoogleResponse, and it's probably buried somewhere in that "result" instance.

    • @elija.
      @elija. 3 роки тому

      @@RoundTheCode i tried it already nothing there. i did it with another method. thanks anyways

  • @md.tahmidmozaffar9135
    @md.tahmidmozaffar9135 4 роки тому +1

    I just started learning ASP Net Core stuff last month. This is just what I was looking for. Thank you very much. Subscribed.

    • @RoundTheCode
      @RoundTheCode  4 роки тому

      Good to hear. Also, check out our new code examples page at www.roundthecode.com/code-examples.

  • @iyashasgowda
    @iyashasgowda 4 роки тому

    Thank you for explaining google authentication in very simple way, hope you might do Microsoft authentication too in next videos

    • @RoundTheCode
      @RoundTheCode  4 роки тому

      It will be similar to Google from an ASP.NET Core point of view. But, you will have to set up an app with Microsoft for the client Id/secret.

    • @iyashasgowda
      @iyashasgowda 4 роки тому

      @@RoundTheCode Thanks, I was able to implement microsoft login.

  • @rvcits
    @rvcits 3 роки тому +1

    Good day sir. Can you please have tutorial of google authentication in ASP.NET Core in .NET 6. I encounter a problem after I get authenticated. Please help me

    • @RoundTheCode
      @RoundTheCode  3 роки тому +2

      Thanks for your comment Roberto. I will bare that idea in mind when planning for my next videos.

  • @sunwado
    @sunwado 4 роки тому +1

    Excellent video very informative

  • @paoluccij
    @paoluccij 3 роки тому

    in NET CORE 5 not have "Controllers Folder",

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      Hi Jose,
      ASP.NET Core in .NET 5 does have the controllers folder when you create an MVC app.
      See our video on dependency injection which is an ASP.NET Core in .NET 5 MVC app.
      ua-cam.com/video/EjFE5d2lCV4/v-deo.html

  • @onurtekin8018
    @onurtekin8018 2 роки тому

    'Exception: The oauth state was missing or invalid.' i stuck with this error :/

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      Hi Onur,
      Make sure that the value in RedirectUri is routing properly.
      Otherwise, you'll need to share your code in GitHub as it's difficult to understand what's gone wrong.

  • @aniljain50
    @aniljain50 2 роки тому

    If I press back button and re authenticate then I get exception: An error was encountered while handling the remote login.

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      Hi Anil,
      You'll need to share your code as I'm not sure why you are getting that error.

    • @anilkumarmootha3738
      @anilkumarmootha3738 2 роки тому

      Hi, Its the same code whatever you shared. Between, how do I share my code. Here itself?

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      @@anilkumarmootha3738 No you will need to create a GitHub repo and push it to that.

  • @danielluigi7952
    @danielluigi7952 3 роки тому

    What if I've more than 1 Login method(1. Google Auth, 2. Login via Database) and I want to let the user pick which method to use in order to login?

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      As mention on our Discord server to you, Identity Server has a lot of stuff to do with roles and permissions. You can use it with ASP.NET Core middleware like Google authentication.

  • @ankxnjst
    @ankxnjst 4 роки тому

    Would this work on asp net core web application(without MVC)?

    • @RoundTheCode
      @RoundTheCode  4 роки тому

      You can add the GoogleAuthentication plugin into any ASP.NET Core application. The question would be how you would build the login page to challenge Google.

  • @johnfox4914
    @johnfox4914 2 роки тому

    I don''t understand. The things you do should not works because the redirect Uri you provide in the console googleCloud does not match any of your API URL...

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      It won't. The "/signin-google" endpoint is setup within the Microsoft.AspNetCore.Authentication.Google package.

  • @lamax847
    @lamax847 4 роки тому

    Why authorization in url "/account/google-login" if we set authorized redirect uri "/sigin-google"? How it worls?

    • @RoundTheCode
      @RoundTheCode  4 роки тому +1

      So, "/account/google-login" sets a challenge which redirects to the Google Login screen.
      I'm assuming in the "Microsoft.AspNetCore.Authentication.Google" library, it has a "/signin-google" endpoint set up that looks out for the response from Google. From there, it can authenticate the user, and that allows us to display the claims returned from Google.

    • @lamax847
      @lamax847 4 роки тому

      @@RoundTheCode thanks, now i understand

  • @adheeshadeshan608
    @adheeshadeshan608 4 роки тому +1

    Thanks RTC very helpful

  • @raghavgupta7579
    @raghavgupta7579 3 роки тому

    Hi sir, When we run our application and log in using google authentication so I occure "corelaton failed" error and object refrence set null

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      Hello Raghav,
      Please join our Discord server at roundthecode.com/discord, and share your code in a GitHub repository so we can have a look at it in a bit more detail.

  • @sowmyas5606
    @sowmyas5606 3 роки тому

    Is applicable for asp.net Web API ?

    • @RoundTheCode
      @RoundTheCode  3 роки тому +1

      You wouldn't have cookie authentication on an ASP.NET Core Web API.
      Instead, you would use something like OAuth security for that.
      Checkout our videos on that topic:
      ua-cam.com/video/vtMtLpTbnE8/v-deo.html

    • @sowmyas5606
      @sowmyas5606 3 роки тому +1

      @@RoundTheCode ok thanks

  • @AlThePal78
    @AlThePal78 2 роки тому +1

    Should definitely make the solution section smaller so that we can see the whole code. I have to bring in the using Microsoft.AspNetCore.Authentication.Cookies; because I am using VS 2022. Additionally, since that is different how did you create this project. I know it is a MVC but did you use no authentication in it that is not at all in the description. Your video is great so I am trying to make sure I know exactly what you're doing

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      I'd recommend you download the sample for it, then you can see the project for yourself. www.roundthecode.com/asp-net-core-examples/google-authentication-example-mvc-application

    • @AlThePal78
      @AlThePal78 2 роки тому

      @@RoundTheCode I’m the same guy from the server I should delete this

    • @AlThePal78
      @AlThePal78 2 роки тому

      @@RoundTheCode thanks for replying I now have to make work with my database and add what I need to so I can work with what I need for this to add the proper values to my database section

  • @ilkayyGul
    @ilkayyGul 3 роки тому

    How do I save the values ​​in google response to the database?

    • @RoundTheCode
      @RoundTheCode  3 роки тому +1

      You could do it in the normal way. Either by using Entity Framework, or ADO. You have the claims in your app, so you can do what you want with them.

    • @ilkayyGul
      @ilkayyGul 3 роки тому

      @@RoundTheCode Thank you , Is there an instructional video?

  • @2k7Bertram
    @2k7Bertram 2 роки тому

    The RedirectUri doesn't work for me. That route function is never called. Just keep going back to the GoogleLogin()

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      Hi Andre, you have added the RedirectUri into your Google Cloud account?

    • @2k7Bertram
      @2k7Bertram 2 роки тому

      @@RoundTheCode Yes...that appeared to be the issue. 😅 Both Google OAuth and .NET Core are new to me. After I did so everything became clear. Thanks for this awesome tutorial!

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      @@2k7Bertram Thanks Andre. Glad you got it sorted.

  • @prabdeepdhaliwal9725
    @prabdeepdhaliwal9725 3 роки тому

    Hey, thanks for the video!
    For some reason after I sign in via google, I am not redirected anywhere... It just shows that I've signed in on the google button, but I'm still on the login page.
    Also I tried to manually type in an authorized route to see if I'm authenticated but it results in this error:
    NullReferenceException: Object reference not set to an instance of an object.
    on this line:
    var claims = result.Principal.Identities
    Any idea what may be the problem?

    • @RoundTheCode
      @RoundTheCode  3 роки тому +1

      Hi Prabdeep,
      Couple of things to check.
      - Have you input the authorized redirect URI (3:32 in the video)? Make sure the host & port number are the same as your application. Also, check it's https as well.
      - Try a different browser. An ad blocker may be preventing it.
      - Make sure the client ID & secret are correct in your ASP.NET Core application.
      The reason for your NullReferenceException is because Google hasn't successfully authenticated the user.

    • @ehtishamakram4437
      @ehtishamakram4437 2 роки тому

      same issue

  • @pranjalchaudhari4927
    @pranjalchaudhari4927 3 роки тому

    "The oauth state was missing or invalid. An error was encountered while handling the remote login"
    in facebook external login when try to login with another facebook id apart from developer id and my developer id logged in successfully but apart from that no other fb id login always get this error message.
    I also have google login and it is working fine
    can you solve why this happens

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      Hey Pranjal,
      Join us on our Discord server at roundthecode.com/discord.
      Put your code into a GitHub repo & share the link on our Discord server so we can have a look for you.

  • @pgoodboy3
    @pgoodboy3 3 роки тому

    How can I use role based authentication with google auth ?

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      Hi Pejoyable.
      It's not something we have looked into, but doing a search on Google may help you find your answer.

  • @hoangnguyenhuy2210
    @hoangnguyenhuy2210 3 роки тому

    I did, but the url in my google-login return null. Help me ,please

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      Hi Hoàng,
      Not really too sure what you mean by this.
      If recommend sharing your code on GitHub. Then, join us on our Discord server at roundthecode.com/discord and share the GitHub repository on there.
      Thanks.

  • @danielluigi7952
    @danielluigi7952 3 роки тому

    What about logout option?

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      As mentioned on our Discord server to you, you can sign out using HttpContext.SignOutAsync();

  • @rohinirohini532
    @rohinirohini532 Рік тому

    How to add this google sign in login page

  • @hanh.trinh.yeu.thuong
    @hanh.trinh.yeu.thuong 3 роки тому +1

    It's very usefull! Thank you! :)

  • @dipanchhabra
    @dipanchhabra 3 роки тому

    hey so, if anybody's listening it is not giving login option, if anybody could help, would be greatly appreciated.

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      Hi Dipan,
      You will need to explain more as to what problem you are having.
      What error message are you getting?
      If you wish, join our Discord server at roundthecode.com/discord and chat about it in there.

    • @dipanchhabra
      @dipanchhabra 3 роки тому

      @@RoundTheCode I'll join for sure, I followed each and every step, there was no error but when I run the app it doesn't show the login page!!

    • @dipanchhabra
      @dipanchhabra 3 роки тому

      @@RoundTheCode i have just started, so if you could keep your language simple I would be very much thankful

  • @JuanPabloUribeRodas
    @JuanPabloUribeRodas 4 роки тому

    Hi, Thank you very much, excellent explanation

  • @ajmitaoufik
    @ajmitaoufik 3 роки тому

    i have this error help me
    An unhandled exception occurred while processing the request.
    Exception: Correlation failed.
    Unknown location
    Exception: An error was encountered while handling the remote login.
    Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      Not sure. Are you able to provide more details? When is this error occuring?

  • @truonghoanglong6941
    @truonghoanglong6941 2 роки тому

    Hello, your videos is amazing and it help me a lot. But i want to ask that after login, how can i log out of that account to log in using another account? Can you give me some idea on how to do it, i'va try many thing but it doesn't seem to work

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      Have you tried HttpContext.SignOutAsync(); ?

  • @Usman-fm2se
    @Usman-fm2se 4 роки тому

    Thank you for such a great video, it was very informative but I need your little bit of help, could you please explain how I get OAuth access token after "google-response"...

    • @RoundTheCode
      @RoundTheCode  4 роки тому

      My example is using Cookie authentication rather than OAuth authentication. If you want to get the claims principal after google-response, you can call HttpContext.User which is where it's stored.

  • @AlThePal78
    @AlThePal78 2 роки тому

    I don't understand why you just don't go to nuget packages and this?

    • @RoundTheCode
      @RoundTheCode  2 роки тому

      It's good to get an understanding of how it works and how to configure it.

    • @AlThePal78
      @AlThePal78 2 роки тому

      @@RoundTheCode I see what I wrote makes no sense I was talking about adding the nuget package through nuget vs typing the commands. For a beginner like me I think it would make sense to go through the manager so when I browse and search, it knows what to do with my mistakes if any when typing :)

  • @rahultnna9198
    @rahultnna9198 3 роки тому +1

    great steps

  • @cissemy
    @cissemy 3 роки тому

    Thanks
    How to add google authentication into .net core web api ?

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      This is more for cookie authentication then using it for an API.
      You would probably want to focus going down the OAuth route for API authentication.
      This is where you give a client ID & secret to the client, and it generates an authorisation code & bearer token.

  • @umeshshelke725
    @umeshshelke725 Рік тому

    Can you please make tutorial on Facebook Authentication using asp net core identify core?

    • @RoundTheCode
      @RoundTheCode  Рік тому

      Already done one some years back.
      ua-cam.com/video/xzcDoUPy8Mk/v-deo.html

  • @marcioaugusto392
    @marcioaugusto392 4 роки тому +1

    Thank you so much for this instructional video. Helped me a lot

  • @333pendejo
    @333pendejo 3 роки тому

    Hello. I would like to thank you for such good help material that you share with us.
    Could you help me with something, I don't know why it gives me "Object Reference not set an instance of an object"? Do you know why it is?
    I have a version of 3.4 Net.core and Microsoft Aspnetcore.authentication.google of 3.1.15

    • @RoundTheCode
      @RoundTheCode  3 роки тому

      Hi Diana. You've created an object, but not created a new instance of it. You need to call the new keyword to create a new instance of it.

  • @emilioignaciovelezsaavedra3173
    @emilioignaciovelezsaavedra3173 3 роки тому +1

    Thx!

  • @dyraksa13688
    @dyraksa13688 4 роки тому +1

    thank for share your knowledge

  • @krakxp
    @krakxp 4 роки тому +1

    Its works,
    Vive!!!
    Viveee!!!
    Muajajajaja muajajaja
    Thank you!!!!!!

    • @RoundTheCode
      @RoundTheCode  4 роки тому

      Good to hear. Thanks for your comments.

  • @deepakpandey9406
    @deepakpandey9406 3 роки тому

    This guy sounds like Jon Skeet 😂

    • @RoundTheCode
      @RoundTheCode  3 роки тому +1

      That because it is me. Jon Skeet. I just got a mask on 🤣

  • @estebanconcha4424
    @estebanconcha4424 4 роки тому +1

    Gracias

  • @hafizabdulmajidwaseer8658
    @hafizabdulmajidwaseer8658 4 роки тому

    useless tutorial, till the end... you should elaborate real-life practical implementation of a live Demo Project...

    • @RoundTheCode
      @RoundTheCode  4 роки тому

      Should I? Ok.

    • @hafizabdulmajidwaseer8658
      @hafizabdulmajidwaseer8658 4 роки тому

      @@RoundTheCode you should take these steps to follow:
      1. Context of tutorial
      2. Which Technology is being used / gonna implement
      3. Show final product / result, in first place
      4. Take fresh solution, to take-on
      5. Tutorial, should've to cover all surrounding concepts i.e. related in this regards... e.g. #Authentication#Authorization etc. how these are implemented in a real-life example... You have to make series of videos, i.e. specifies particular context in broad-manner... !!!
      ...
      People like us, will glad to have this vary RICH contextual based series of Videos...

    • @yaozhang6766
      @yaozhang6766 4 роки тому +2

      This is concise and to the point for anyone looking to just get a skeleton code up and running, which is very appreciated. There are 5hr+ long video series out there already covering a lot more, but at that point it's faster to look at the msdn docs with their dotnet core samples.

    • @aniljain50
      @aniljain50 4 роки тому +1

      @@hafizabdulmajidwaseer8658 Instead of saying useless, you can put recommendations. Its a first step NEAT AND SIMPLE video towards oauth. We can respect the authors time.