Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use DotNetOpenAuth to log into Google, and get user profile

I just want to login with google and want access logged in user's general profile like photo, email address and name, to display on my site. Is it possible with DotNetOpenAuth?

like image 255
Nps Avatar asked Dec 31 '25 08:12

Nps


1 Answers

That's trivially easy. Use OpenID to "just login", instead of OAuth. Take a look at the OpenIdRelyingPartyWebForms or OpenIdRelyingPartyMvc samples for how to log a user in. Since you're only interested in logging the user in with Google, rather than displaying an input box you can just have a "Login with Google" button that calls OpenIdRelyingParty.CreateRequest("https://www.google.com/accounts/o8/id") to initiate a Google login.

As @Lirik pointed out in a comment, you can use AX to retrieve user profile info. However I don't think that will get you the user photo. If Google even makes that available (big if) you may have to use OAuth for that. And I would recommend in that case that you use the "OpenID+OAuth" extension for that, which I believe leads you to the "Google Contacts" sample you have already seen. To change that to retrieve a user photo however, you'd need to review Google's own GData API documentation to see how to retrieve a user photo (if you can).

like image 61
Andrew Arnott Avatar answered Jan 05 '26 14:01

Andrew Arnott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!