I have created a standard ASP.Net site using VS2017 template and add external login using Google and Microsoft.
It was a success. When users first login this way, they will be asked to key in an Alias.
Eg a user may enter "Superman" and in their next log in their Alias is displayed on the menu bar.
I found the log file in App_Data is logging using their alias (eg superman) which is totally useless for me for identity purpose.
I need to get their email account name instead as "superman" does not enable me to identify the person.
(eg if it is SteveJob@gmail.com then I simply need SteveJob or simply his email.)
Some people gave me this code below to pull their login into label1.text, it works but it is getting their Alias again only.
Is there way to get their username instead. I do not intend to get their profile, just username of email will do.
What I am trying now is I changed "Name" in the code below to something else, and as I type a dot VS intellisense gives me a lot of choices such as Email, First Name, Gender etc. so it seems this is possible.
But on-run, all these 3 returns a blank value. Seems we are not able to get anything from Google/Microsoft.
Please anyone inform me what is still missing ? I do not need his profile details, just simple username is sufficient.
Thanks a lot.
var identity = (ClaimsIdentity)HttpContext.Current.User.Identity;
var name = identity.Claims.FirstOrDefault(m => m.Type == System.Security.Claims.ClaimTypes.Name).Value;
Thanks. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
'AuthenticationManager' does not contain a definition for 'GetExternalLoginInfoAsync()'
I am using Web Form. Please help. Thanks
If you have an existing project that doesn’t have any identity features installed you’ll need to get the right assemblies into your project.
Luckily, thanks to the power of NuGet, to get just the core identity features you can add just the following packages to get all the references you needed for the core identity features plus a few of the external providers needed.
Microsoft.Owin.Host.SystemWeb
Microsoft.Owin.Security.Cookies
The first two packages are enough to light up the OWIN identity framework.
You’ll also need to install the the specific external provider packages:
Microsoft.Owin.Security.Google
Microsoft.Owin.Security.Twitter
Owin.Security.Providers
The provider packages add support for specific external providers you can log in with.
Member
738 Points
2365 Posts
How to get simple username in Google login to my ASP.Net Site
Jun 28, 2017 05:19 AM|hkbeer|LINK
I have created a standard ASP.Net site using VS2017 template and add external login using Google and Microsoft.
It was a success. When users first login this way, they will be asked to key in an Alias.
Eg a user may enter "Superman" and in their next log in their Alias is displayed on the menu bar.
I found the log file in App_Data is logging using their alias (eg superman) which is totally useless for me for identity purpose.
I need to get their email account name instead as "superman" does not enable me to identify the person.
(eg if it is SteveJob@gmail.com then I simply need SteveJob or simply his email.)
Some people gave me this code below to pull their login into label1.text, it works but it is getting their Alias again only.
Is there way to get their username instead. I do not intend to get their profile, just username of email will do.
What I am trying now is I changed "Name" in the code below to something else, and as I type a dot VS intellisense gives me a lot of choices such as Email, First Name, Gender etc. so it seems this is possible.
But on-run, all these 3 returns a blank value. Seems we are not able to get anything from Google/Microsoft.
Please anyone inform me what is still missing ? I do not need his profile details, just simple username is sufficient.
Thanks a lot.
www.developerfusion.com/tools/convert/csharp-to-vb/
Star
8650 Points
2882 Posts
Re: How to get simple username in Google login to my ASP.Net Site
Jun 29, 2017 03:34 AM|Cathy Zou|LINK
Hi hkbeer
Try to using the following code:
For more information, please refer to the following links:
https://dotnetcodr.com/2014/07/07/introduction-to-forms-based-authentication-in-asp-net-mvc5-part-5-claims/
Best regard
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
738 Points
2365 Posts
Re: How to get simple username in Google login to my ASP.Net Site
Jun 29, 2017 11:39 AM|hkbeer|LINK
Thanks a lot
I get this error
'AuthenticationManager' does not contain a definition for 'GetExternalLoginInfoAsync()'
I am using Web Form. Please help. Thanks
www.developerfusion.com/tools/convert/csharp-to-vb/
Participant
970 Points
475 Posts
Re: How to get simple username in Google login to my ASP.Net Site
Aug 11, 2017 06:31 AM|zxj|LINK
Hi hkbeer,
If you have an existing project that doesn’t have any identity features installed you’ll need to get the right assemblies into your project.
Luckily, thanks to the power of NuGet, to get just the core identity features you can add just the following packages to get all the references you needed for the core identity features plus a few of the external providers needed.
The first two packages are enough to light up the OWIN identity framework.
You’ll also need to install the the specific external provider packages:
The provider packages add support for specific external providers you can log in with.
Regards,
zxj