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
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.)
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!!
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); }
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)};
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.
Thank you very much Venkat, could you kindly explain why this line (var info = await signInManager.GetExternalLoginInfoAsync();) return null , when I use AzureAD login
try to check ConfigureExternalAuthenticationProperties and what you pass to it some time when you pass not valid parameter GetExternalLoginInfoAsync fail
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.
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.
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.
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.
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 });
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.
@@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'.
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.
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
Awesome explanation as usual. To ensure continuity I hope you plan to make tutorial on azure. Thank you for your continued effort.
Thank you .. great video
Best teacher ever seen kudvenkat
I think in the whole world there is no anyone like Venkat sir...
Great tutorial. Really helped break down the concept of external login for me. Thanks Kudvenkat
you are living legend I am considering tattooing your name, watching other people explaining this is so painful comparing to you.
You are great ... thanks as always ...
Thanks for the video 👍
Thank u bro. It's really helped me.
helpful video, thank you!
Thank you, man!
Hey Venkat, what if we don’t use identity and depend entirely on external authentication..?? Can we still use call back??
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
Why the Manage menu is showing for external new user sign in ? External user doesn't have any roles..right ?
I have a question Venkat!
In what situation we don't receive email from the provider?
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.)
Hi @Conax learn I am getting the error as insert statement casing conflict with primary key constraints
Is there any solution
Hi Team got the resolution . Solution is working fine . Many thanks . I was doing some mistakes and now realised
where is applicationuser belong . I get red squiggly
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!!
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);
}
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)};
Remember for locally registered users, we have been using email address as the value for both email and username.
Venkat, could you kindly explain why this line (var info = await signInManager.GetExternalLoginInfoAsync();) return null , when I use AzureAD login :(
from where ApplicatioUser class belongs to?
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.
Nice video. Dear sir, please make sone videos on IndentityServer 4.0
Did kudvenkat discard the employee entity and replace it with an identity use? Can someone clarify please. I'm confused.
Thank you very much Venkat, could you kindly explain why this line (var info = await signInManager.GetExternalLoginInfoAsync();) return null , when I use AzureAD login
try to check ConfigureExternalAuthenticationProperties and what you pass to it some time when you pass not valid parameter GetExternalLoginInfoAsync fail
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
Sir to buy, how to improve logic building because in ready project we get problems fixing errors and putting new logic,
Best teaching. Please introduced your self with face.i want to see you. Please just 1 video
Mee too....
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.
Dear Venkat,
Since we have foreign key constraint, how can we delete users of whom we have data in our AspnetUserLogins Table?
My guess is to check out userManager.RemoveLoginAsync().
ah finally got this background music at the end of the video its Crispy Chris Judy 2
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.
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.
i'm just little bit confuse. why we create user for external login. why it doesn't use external login credentials ??
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.
how set only 5 instance of a class will created not more than that??
Thanks very much.
Can you help to integrate google authentication with .Net project, instead of .Net core?
I am getting invalid oauth state, or missing state any idea bro?????
Can you please cover Blazor as well simultaneously, ASAP please
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.
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
}
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.
@@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'.
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.
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.
Please make a video on .net core cookie authentication
+
returnUrl = returnUrl ?? Url.Content("~/");
why write
this line
That link checks if returnUrl is null, if it's null, then it set the returnUrl content to Home Page ("~/")
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
how set only 5 instance of a class will created not more than that??