OAuth protocol is a protocol which is implemented by a lot of famous social networks and is the fundamental key to working with most of their APIs, specially to access to methods which requires some of identity of the requester. So if you want to integrate your website with Facebaook or Google Plus or LinkedIn etc probably your first step would be to handle OAuth protocol.
Also it is a common practice to use OAuth for authenticating user's in your website. Instead of the classic set of username/password credentials, you can simply deliver the user identification to these social networks and ask for user's primary set of information like name, date of birth, gender etc through their API.
OAuth protocol is a complete protocol as it considers all the parties(one which needs to authorize, one which need to make an authorized request, end user who authorizes) and all common scenarios in ways of communication between parties.
DotNetAuth is a an implementation of the OAuth protocol which only supports the consumption of protocol, and it is only for server side flow. So if you are the developing a website which wants to makes user-authorized requests to social network sites like Facebook or Google API this library is for. Also this library helps you take advantage of the OAuth protcol to identify users of your website and use OAuth for user membership(sign up, sign in features).
Source Code:
https://bitbucket.org/samnaseri/dotnetauth
Nuget Packages:
Install-Package DotNetAuth
Install-Package DotNetAuth.Profiles
Asp.Net MVC Sample:
This is just a sample to show what it would look like.
Just add above packages and then you can have the following methods in your ProfileController:
public class ProfileController : Controller { ProfileProperty[] requiredProperties = new[] { ProfileProperty.Email, ProfileProperty.DisplayName, ProfileProperty.UniqueID, ProfileProperty.DisplayName }; // GET: /Profile/ [HttpGet] public ActionResult Index() { return View(); } public RedirectResult Login() { var userProcessUri = Url.Action("Callback", "Profile", null, protocol: Request.Url.Scheme); var provider = LoginProvider.Get(LoginProviderRegistry.Facebook.Fullname); var authorizationUrl = DotNetAuth.Profiles.Login.GetAuthenticationUri(provider, new Uri(userProcessUri), new DefaultLoginStateManager(Session), requiredProperties); authorizationUrl.Wait(); return Redirect(authorizationUrl.Result.AbsoluteUri); } // GET: /Process [HttpGet] public ActionResult Callback(string providerName) { var userProcessUri = Url.Action("Callback", "Profile", null, protocol: Request.Url.Scheme); var provider = LoginProvider.Get(LoginProviderRegistry.Facebook.Fullname); var profile = DotNetAuth.Profiles.Login.GetProfile(provider, Request.Url, userProcessUri, new DefaultLoginStateManager(Session), requiredProperties); profile.Wait(); return Content(profile.Result.ToString()); } }
And that's it.
could we have sample code for asp.net web forms ?
ReplyDeleteA sample code will be provided for Web Forms very soon.
ReplyDeleteNice post very helpful
ReplyDeletedbakings
It is not working for me. and it is not clear to implement.
ReplyDeleteDoes this support Windows Phone 8?
ReplyDeleteIt is only for Asp.Net
DeleteHave you worked on the Web Forms example yet?
ReplyDeleteAre there any examples anywhere of how to implement this?
ReplyDeleteHello Sam,
ReplyDeleteHave you been able to post the Web Forms example?
Web Form? Nice and simple .ASPX so that we can authenticate an end-user from Google?
ReplyDeleteHi Sam!
ReplyDeleteUnder what license is this released? MIT license?
Hi Sam,
ReplyDeleteCan we use this library to do Single Sign on using ADFS 3.0?
Hi Sam,
ReplyDeleteCan we use this library to do Single Sign on using ADFS Windows 2012 R2
Hi Sam,
ReplyDeleteWe Will Implement this code
In your source code there is cs file name KEY but its not present in folder so please give me that key.cs file
ReplyDeleteIs it possible to use this library in a standalone (command line) program? If so, can you please post a short example?
ReplyDeleteIs this project still supported and does it support .NET Core 3.x onwards?
ReplyDelete