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!)
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 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
@@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
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.
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.
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.
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,...
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
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?
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 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.
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.
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
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
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.
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.
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.
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...
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.
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.
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
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
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
@@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
@@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!
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?
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.
"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
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.
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.
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.
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()
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
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"...
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.
@@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 :)
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.
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 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...
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.
@@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.
Thinking of doing a full course on Google Authentication in ASP.NET Core. Let us know which areas you would like to be covered.
Bro it ferfect but mor than perfect. please explain bigger size. Your screen resulation so b big.
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!)
Thanks Ilya.
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.
Have you added your live domain as an "Authorised Redirect URI"?
So you should create a new "Authorised Redirect URI" of {livedomain}/signin-google.
@@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
@@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
Please provide solution on this, Getting the same 500 error in production
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.
That's good to hear. It's good that ASP.NET Core has it's own NuGet packages for authentication.
Hi, can you tell us how to add a logout button?
@@chandankarmakar6651 Steps for logging out :
1. Redirect the user to the login page.
2. Clear the saved cookie on logout button clicked.
Excellent tutorial and very simple!!
Thanks for your comments.
This is what i was actually looking for , thanks
Thanks for your comment, Sanjay.
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.
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.
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,...
Hi Hao. Not sure to be honest. Never had any experience with Flutter.
Thanks a lot, its works you saved me hours to deal with Authentication roles and databases n just use this service ♥that
Good to hear Tait.
Very informative. Keep up the good work bro :)
Thanks Rohail.
I encounter cors error when i run the project with angular although added the cors policy. Do you know how to fix?
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
@@RoundTheCode Ok thank you so much for support. Im gonna check this out
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?
Thanks for the tutorial
Thanks Amal.
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.
Not sure if I follow what you are saying?
@@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.
I tried and its working, Thank you for the detailing explanations
Good to hear Ranjit.
You're so awesome, you really know your stuff, great content :)
Thanks Matt.
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.
With your Google project, you'd have to set up a separate sign in URL for each system I believe.
what about getting the code to create access token?
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.
@@RoundTheCode i tried it already nothing there. i did it with another method. thanks anyways
I just started learning ASP Net Core stuff last month. This is just what I was looking for. Thank you very much. Subscribed.
Good to hear. Also, check out our new code examples page at www.roundthecode.com/code-examples.
Thank you for explaining google authentication in very simple way, hope you might do Microsoft authentication too in next videos
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.
@@RoundTheCode Thanks, I was able to implement microsoft login.
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
Thanks for your comment Roberto. I will bare that idea in mind when planning for my next videos.
Excellent video very informative
Glad it was helpful!
in NET CORE 5 not have "Controllers Folder",
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
'Exception: The oauth state was missing or invalid.' i stuck with this error :/
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.
If I press back button and re authenticate then I get exception: An error was encountered while handling the remote login.
Hi Anil,
You'll need to share your code as I'm not sure why you are getting that error.
Hi, Its the same code whatever you shared. Between, how do I share my code. Here itself?
@@anilkumarmootha3738 No you will need to create a GitHub repo and push it to that.
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?
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.
Would this work on asp net core web application(without MVC)?
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.
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...
It won't. The "/signin-google" endpoint is setup within the Microsoft.AspNetCore.Authentication.Google package.
Why authorization in url "/account/google-login" if we set authorized redirect uri "/sigin-google"? How it worls?
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.
@@RoundTheCode thanks, now i understand
Thanks RTC very helpful
Happy to help
Hi sir, When we run our application and log in using google authentication so I occure "corelaton failed" error and object refrence set null
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.
Is applicable for asp.net Web API ?
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
@@RoundTheCode ok thanks
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
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
@@RoundTheCode I’m the same guy from the server I should delete this
@@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
How do I save the values in google response to the database?
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.
@@RoundTheCode Thank you , Is there an instructional video?
The RedirectUri doesn't work for me. That route function is never called. Just keep going back to the GoogleLogin()
Hi Andre, you have added the RedirectUri into your Google Cloud account?
@@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!
@@2k7Bertram Thanks Andre. Glad you got it sorted.
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?
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.
same issue
"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
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.
How can I use role based authentication with google auth ?
Hi Pejoyable.
It's not something we have looked into, but doing a search on Google may help you find your answer.
I did, but the url in my google-login return null. Help me ,please
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.
What about logout option?
As mentioned on our Discord server to you, you can sign out using HttpContext.SignOutAsync();
How to add this google sign in login page
Yes that is what this video is about.
It's very usefull! Thank you! :)
Thanks for the comment.
hey so, if anybody's listening it is not giving login option, if anybody could help, would be greatly appreciated.
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.
@@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!!
@@RoundTheCode i have just started, so if you could keep your language simple I would be very much thankful
Hi, Thank you very much, excellent explanation
Thanks for your comments.
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()
Not sure. Are you able to provide more details? When is this error occuring?
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
Have you tried HttpContext.SignOutAsync(); ?
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"...
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.
I don't understand why you just don't go to nuget packages and this?
It's good to get an understanding of how it works and how to configure it.
@@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 :)
great steps
Thanks Rahul
Thanks
How to add google authentication into .net core web api ?
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.
Can you please make tutorial on Facebook Authentication using asp net core identify core?
Already done one some years back.
ua-cam.com/video/xzcDoUPy8Mk/v-deo.html
Thank you so much for this instructional video. Helped me a lot
You're welcome!
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
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.
Thx!
Thanks for the comment.
thank for share your knowledge
My pleasure
Its works,
Vive!!!
Viveee!!!
Muajajajaja muajajaja
Thank you!!!!!!
Good to hear. Thanks for your comments.
This guy sounds like Jon Skeet 😂
That because it is me. Jon Skeet. I just got a mask on 🤣
Gracias
Thanks for your comments
useless tutorial, till the end... you should elaborate real-life practical implementation of a live Demo Project...
Should I? Ok.
@@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...
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.
@@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.