ExternalLoginCallback action in asp net core

Поделиться
HTML-код
  • Опубликовано: 9 окт 2024
  • How to handle login information received from the external login provider such as Google for example.
    Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.
    / @aarvikitchen5572
    We will be redirected to Google sign-in page, if we click on the Google button on the Login view.
    Text version of the video
    csharp-video-t...
    Slides
    csharp-video-t...
    ASP.NET Core Text Articles & Slides
    csharp-video-t...
    ASP.NET Core Tutorial
    • ASP.NET core tutorial ...
    Angular, JavaScript, jQuery, Dot Net & SQL Playlists
    www.youtube.co...

Комментарии • 63

  • @iliesbenhaddouche2970
    @iliesbenhaddouche2970 5 лет назад +6

    Awesome explanation as usual. To ensure continuity I hope you plan to make tutorial on azure. Thank you for your continued effort.

  • @fahedabdelhalim3019
    @fahedabdelhalim3019 5 лет назад +2

    Thank you .. great video
    Best teacher ever seen kudvenkat

    • @piasuddin3846
      @piasuddin3846 5 лет назад

      I think in the whole world there is no anyone like Venkat sir...

  • @Fr3dii
    @Fr3dii 3 года назад

    Great tutorial. Really helped break down the concept of external login for me. Thanks Kudvenkat

  • @LT-yk7xy
    @LT-yk7xy 2 года назад

    Hey Venkat, what if we don’t use identity and depend entirely on external authentication..?? Can we still use call back??

  • @davidgates5189
    @davidgates5189 3 года назад

    you are living legend I am considering tattooing your name, watching other people explaining this is so painful comparing to you.

  • @daophilac
    @daophilac 4 года назад

    I have a question Venkat!
    In what situation we don't receive email from the provider?

  • @loveunimeanit
    @loveunimeanit 5 лет назад

    You are great ... thanks as always ...

  • @mohamedashash27
    @mohamedashash27 3 года назад

    I'm wondering if i want to change the view page after we signed in what code i will change?
    example : after login we go to Account/Index , how change it to another controll like Accountsettings/change
    , etc

  • @vladkorsak2163
    @vladkorsak2163 4 года назад

    Thank u bro. It's really helped me.

  • @ByMyKolaps
    @ByMyKolaps 3 года назад

    Thank you, man!

  • @aleksandrzhadetsky2535
    @aleksandrzhadetsky2535 4 года назад

    helpful video, thank you!

  • @muhammadwaqasiqbal8243
    @muhammadwaqasiqbal8243 4 года назад

    Hi Sir Venkat!
    I tried to login using an account which i hadnt registered and i was expecting it will show the error messages we have assigned to viewbag but instead it thew an exception! my question is when are we going to see the error messages of claim types we have assigned to viewbag.

  • @Vagelis_Prokopiou
    @Vagelis_Prokopiou 5 лет назад

    Thanks for the video 👍

  • @suatsuphi
    @suatsuphi 3 года назад

    thanks kudvenkat, I have problem with hashtag ? how to remove it and why I get it ? you have same problem in your video time: 12:36

  • @nishanthmohan
    @nishanthmohan 4 года назад

    Why the Manage menu is showing for external new user sign in ? External user doesn't have any roles..right ?

  • @mohammedaljohani7792
    @mohammedaljohani7792 4 года назад

    Venkat, could you kindly explain why this line (var info = await signInManager.GetExternalLoginInfoAsync();) return null , when I use AzureAD login :(

  • @javaguitarist
    @javaguitarist 4 года назад +1

    At 7:33, how can ClaimTypes.Email possibly return both the UserName and the Email properties? Shouldn't it be something like ClaimTypes.UserName for the UserName?
    user = new ApplicationUser{UserName = info.Principal.FindFirstValue(ClaimTypes.Email),
    Email = info.Principal.FindFirstValue(ClaimTypes.Email)};

    • @conaxlearn8566
      @conaxlearn8566 4 года назад +2

      Remember for locally registered users, we have been using email address as the value for both email and username.

  • @khalilaibrahim1278
    @khalilaibrahim1278 4 года назад

    Thank you very much Venkat, could you kindly explain why this line (var info = await signInManager.GetExternalLoginInfoAsync();) return null , when I use AzureAD login

    • @mostafaanssary6135
      @mostafaanssary6135 4 года назад

      try to check ConfigureExternalAuthenticationProperties and what you pass to it some time when you pass not valid parameter GetExternalLoginInfoAsync fail

  • @conaxlearn8566
    @conaxlearn8566 4 года назад

    Question 1: So when the first sign in attempt failed by calling ExternalLoginSignInAsync(), we do a bunch of stuff. Then when we retry sign in, why are we calling SignInAsync() instead of calling ExternalLoginSignInAsync() again?
    Question 2: Theoretically if GetExternalLoginInfoAsync() returns the info with the user's email address, all we need to do is to try and find the user by calling FindByEmailAsync(). If FindByEmailAsync() doesn't return the user then we call CreateAsync(). After that, we can call SignInAsync() to sign in the user. All this without the need of using ExternalLoginSignInAsync() and the AspNetUserLogins table. So why can't we do it this way? (I have test coded this way to prove that it works.)

    • @sahiltiwari3518
      @sahiltiwari3518 3 года назад

      Hi @Conax learn I am getting the error as insert statement casing conflict with primary key constraints

    • @sahiltiwari3518
      @sahiltiwari3518 3 года назад

      Is there any solution

    • @sahiltiwari3518
      @sahiltiwari3518 3 года назад

      Hi Team got the resolution . Solution is working fine . Many thanks . I was doing some mistakes and now realised

  • @thesuperiorman8342
    @thesuperiorman8342 5 лет назад

    Did kudvenkat discard the employee entity and replace it with an identity use? Can someone clarify please. I'm confused.

  • @itsrahimuddinkhan
    @itsrahimuddinkhan 5 лет назад

    Nice video. Dear sir, please make sone videos on IndentityServer 4.0

  • @pradeepyadavup8189
    @pradeepyadavup8189 5 лет назад

    Sir to buy, how to improve logic building because in ready project we get problems fixing errors and putting new logic,

  • @senolkurt7864
    @senolkurt7864 5 лет назад

    Dear Venkat,
    Since we have foreign key constraint, how can we delete users of whom we have data in our AspnetUserLogins Table?

    • @conaxlearn8566
      @conaxlearn8566 4 года назад

      My guess is to check out userManager.RemoveLoginAsync().

  • @joaolopes9926
    @joaolopes9926 Год назад

    I cannot SignIn in DEBUG MODE "Couldn’t sign you in - This browser or app may not be secure". why? I do everything like the video said.

  • @akashhalwai291
    @akashhalwai291 2 года назад +1

    from where ApplicatioUser class belongs to?

  • @souravsingha3340
    @souravsingha3340 5 лет назад

    Best teaching. Please introduced your self with face.i want to see you. Please just 1 video

  • @aslantechnitrix3655
    @aslantechnitrix3655 4 года назад

    i'm just little bit confuse. why we create user for external login. why it doesn't use external login credentials ??

    • @conaxlearn8566
      @conaxlearn8566 4 года назад

      Regardless using local or external login, you need to store all your users in one table so that you can make sure they have unique user Id in order to perform actions that depends on their user Id, like assigning roles and claims.

  • @prodiptamondal1758
    @prodiptamondal1758 4 года назад

    Thanks very much.
    Can you help to integrate google authentication with .Net project, instead of .Net core?

  • @senolkurt7864
    @senolkurt7864 5 лет назад +1

    With the last changes we made, when we use local login and if the ModelState is not valid, we get null reference exception because of the ExternalLogins property!!

    • @donoboyle8718
      @donoboyle8718 4 года назад

      I changed the login method to take care not to post any null references to the view.
      [HttpPost]
      [AllowAnonymous]
      public async Task Login(LoginViewModel model, string returnUrl)
      {
      if (ModelState.IsValid)
      {
      var result = await signInManager.PasswordSignInAsync(
      model.Email, model.Password, model.RememberMe, false);
      if (result.Succeeded)
      {
      if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
      {
      return Redirect(returnUrl);
      }
      else
      {
      return RedirectToAction("index", "home");
      }
      }
      else
      {
      // in the event of a login failure we make sure to take care of any null values and refresh the external login
      LoginViewModel failmodel = new LoginViewModel
      {
      Email = model.Email,
      Password = model.Password,
      RememberMe = model.RememberMe,
      ReturnUrl = returnUrl,
      ExternalLogins = (await signInManager.GetExternalAuthenticationSchemesAsync()).ToList()
      };
      ModelState.AddModelError(string.Empty, "Invalid Login Attempt");
      return View(failmodel);
      }

      }

      return View(model);
      }

  • @lifetraveler8008
    @lifetraveler8008 4 года назад

    Can anyone help me with this
    I have a question about how a project is built in a real life. I am building one for my resume, I am being told to breakdown the project into following
    1. Class Library
    projectName.Application
    projectName.Core
    projectName.Infrastructure
    2. Asp.net Web
    projectName.Web
    I want to know Is this the right way of doing it? . Couldn't find answer on the internet.

  • @srikanthek737
    @srikanthek737 5 лет назад

    Can you please cover Blazor as well simultaneously, ASAP please

  • @hassaanmasood1419
    @hassaanmasood1419 4 года назад

    What you are explaining is already written in Visual Studio template... Create a video on securing additional data/claims from external provider.. This is something on where there's no proper information available on internet. Even the Microsoft documentation is properly written.

  • @_samirdahal
    @_samirdahal 4 года назад +1

    ah finally got this background music at the end of the video its Crispy Chris Judy 2

  • @gkmishra2009
    @gkmishra2009 5 лет назад

    how set only 5 instance of a class will created not more than that??

  • @manasianil
    @manasianil 3 года назад +1

    where is applicationuser belong . I get red squiggly

  • @downunder365
    @downunder365 4 года назад

    I am getting invalid oauth state, or missing state any idea bro?????

  • @abinashmati1732
    @abinashmati1732 5 лет назад

    Please make a video on .net core cookie authentication

  • @javaguitarist
    @javaguitarist 4 года назад

    I'm on asp.net core 3.1. Has anyone made this work on 3.1? I triple checked all the code. It matches his code. The Google button never hits the ExternalLoginCallback method, only hitting the ExternalLogin(). The redirectUrl is correct. It just keeps going back to the Login page but keeps on adding duplicates of the previous query string. I deleted the gmail user record in AspNetUser when it sort of worked before (never again) and AspNetUserLogins. Cleared Chrome cache and logged out of Google in Chrome. It appears that Google's oauth has changed and this method of using it no longer works.

    • @conaxlearn8566
      @conaxlearn8566 4 года назад

      Have you resolved it? I am using 3.1 and it is working for me. I'm doing exactly what's taught in the video. Only thing different is that I have to manually install Microsoft.AspNetCore.Authentication.Google. But since you're using 3.1, I'm sure you had done the same.
      The symptom you described did sound like you were redirected from Google back to ExternalLogin action instead of ExternalLoginCallback action.i.e.
      You might have this:
      public IActionResult ExternalLogin(string provider, string returnUrl)
      {
      var redirectUrl = Url.Action("ExternalLogin", "Account", new { ReturnUrl = returnUrl });
      // rest of the code ignored here
      }
      instead of this:
      public IActionResult ExternalLogin(string provider, string returnUrl)
      {
      var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });

      // rest of the code ignored here
      }

    • @opaleyetayo2964
      @opaleyetayo2964 4 года назад

      Please I am a new programmer. Are we meant to know how to re-write this code by ourself or just know how to tweak the code to work. I have seen a whole lot of codes for the oauth most especially. I will be glad if you can find time to reply me.

    • @conaxlearn8566
      @conaxlearn8566 4 года назад

      @@opaleyetayo2964 Welcome to the programming world! Video tutorials like this are meant to give you a ground knowledge and examples of how to do the common things. I'm sure when you start to work on real projects you will need to do a lot of Googling on more 'how tos'.

    • @AkshayKumar-dz5ts
      @AkshayKumar-dz5ts 4 года назад

      This happened to me too today, and i put breakpoints to see whats going on and i found that Url.Action(...) returns null for some reason in asp.net core 3.x
      If you did find a workaround, do let me know.
      Edit: Hello people, if you did face this problem, then just try to add an action with the same name as the one your provided in Url.Action(...) and it should work as expected.
      Behind the scenes : asp.net tries to find this particular action in the controller you mentioned and if it fails to find such a route, then it returns null. This was not the case before core 3.x.

    • @javaguitarist
      @javaguitarist 4 года назад +1

      Opaleye Tayo I don’t think this is an easy fix. Both asp.net core and Google authentication have changed since this video was made.

  • @التاريخ-ح4ظ
    @التاريخ-ح4ظ 4 года назад

    returnUrl = returnUrl ?? Url.Content("~/");
    why write
    this line

    • @deepakpandey9406
      @deepakpandey9406 3 года назад +2

      That link checks if returnUrl is null, if it's null, then it set the returnUrl content to Home Page ("~/")

  • @mouxez
    @mouxez 3 года назад

    +

  • @osamadammag6303
    @osamadammag6303 6 месяцев назад

    AuthenticationFailureException: OAuth token endpoint failure: invalid_client;Description=Unauthorized Unknown location AuthenticationFailureException: An error was encountered while handling the remote login. Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync() I got this error once I click on the button

  • @gkmishra2009
    @gkmishra2009 5 лет назад

    how set only 5 instance of a class will created not more than that??