1. Trang chủ
  2. » Tất cả

Open ID

7 333 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 7
Dung lượng 183 KB

Nội dung

To secure websites, we usually create user database and develop a login page to authenticate the user. If you have several websites, creating separate user login for each site is time consuming and not favorable to your users because they have to login to each site separately. Share on linkedin Share on facebook Share on twitter Share on email More Sharing Services 0 OpenID was developed to solved such authentication hassles. It is an open standard for developers that enables them to authenticate their users in a decentralized manner. For end-users, OpenID allows them to consolidate their digital identities. Major web services that supports OpenID are Google, Yahoo and Facebook. If you use OpenID with your website, you allow users to login to your site using their Google, Yahoo or Facebook accounts. The authentication will be hosted by the OpenID provider, so no need to maintain the user details on your side except the Identifier returned by the provider. On this article, I will show you a ASP.NET sample code I made that use OpenID Authentication to verify Google Account. To accomplish the authentication, I used the C# library called DotNetOpenAuth. Here is the step-by-step procedure to implement it on your ASP.NET application. 1. Download the DotNetOpenAuth Libraries. Choose the most appropriate version for development platform. 2. Extract the downloaded compressed file on your hard drive. 3. On your project, Add Reference to "DotNetOpenAuth.dll" 4. On your login page's HTML Code, paste the following. view plainprint? <form id="form1" runat="server"> <div id="loginform"> <div id="NotLoggedIn" runat="server"> Log in with <img src="http://www.google.com/favicon.ico" /> <asp:Button ID="btnLoginToGoogle" Runat="server" Text="Google" OnCommand="OpenLogin_Click" CommandArgument="https://www.google.com/accounts/o8/id" /> <p /><asp:Label runat="server" ID="lblAlertMsg" /> </div> </div> </form> Take note of the URL: https://www.google.com/accounts/o8/id - this is the unique OpenID URL of Google Account. 5. Include the following namespaces on your "Using" directive. view plainprint? using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.RelyingParty; 6. On the Page_Load & OpenLogin_Click, use the following codes. view plainprint? protected void Page_Load(object sender, EventArgs e) { OpenIdRelyingParty rp = new OpenIdRelyingParty(); var r = rp.GetResponse(); if (r != null) { switch (r.Status) { case AuthenticationStatus.Authenticated: NotLoggedIn.Visible = false; Session["GoogleIdentifier"] = r.ClaimedIdentifier.ToString(); Response.Redirect("Main.aspx"); //redirect to main page of your website break; case AuthenticationStatus.Canceled: lblAlertMsg.Text = "Cancelled."; break; case AuthenticationStatus.Failed: lblAlertMsg.Text = "Login Failed."; break; } } protected void OpenLogin_Click(object src, CommandEventArgs e) { string discoveryUri = e.CommandArgument.ToString(); OpenIdRelyingParty openid = new OpenIdRelyingParty(); var b = new UriBuilder(Request.Url) { Query = "" }; var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri); req.RedirectToProvider(); } 7. Run the project. It should look like the following screens. Dot net o auth At the time of me answering this question, DotNetOpenAuth has a public Community Tech Preview (CTP) which is available to download. 1. Download that source code. Should be a .7z file. You can use 7-Zip to unzip the code if you don't already have it (it's free). 2. Open up the samples source code solution in Visual Studio. I'm using VS2010 but I think there's also a VS2008 solution file. 1. Now, open up the web.config file for the OAuthClient project. 2. Next, edit the following settings :- <!-- Facebook sign-up: http://developers.facebook.com/setup/ --> <add key="facebookAppID" value="------"/> <add key="facebookAppSecret" value="------------"/> You can get these values from your application on Facebook. 1. Debug/Run the OAuthClient Web Application. This will start an instance of Cassini/Visual Studio Developer Server and a web browser should open: Voilà! you can now connect to Facebook to log in. If you get errors, then you need to make sure that: 1. You've manually changed the Facebook app settings in your web.config file. 2. You've correctly setup your app settings in the Facebook developer website. . OpenID allows them to consolidate their digital identities. Major web services that supports OpenID are Google, Yahoo and Facebook. If you use OpenID. view plainprint? using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.RelyingParty; 6. On the Page_Load & OpenLogin_Click, use the following

Ngày đăng: 08/03/2013, 08:58

Xem thêm

TỪ KHÓA LIÊN QUAN

w