Step 1 log on to the system with an account (6. log on to the website with openid)

Source: Internet
Author: User
Tags html header oauth openid

In my blog yesterday, I introduced the support process for logging on to Yahoo's bbauth in my account logon system.ArticleOfCodeAlthough it is very simple and the article is not long, it is actually the most profound type of research I have studied. It is also my research on bbauth that eventually led me to decide to open-source all of this system ., Today, I want to talk about the implementation of openid. The next article is about how to support Intranet login, later, I may briefly talk about oauth login (if I can study it clearly). Some netizens once asked me when to download the entire code, but I think the code is still very imperfect. the download of code on my website must be completed after every supported login type is introduced. At that time, before New Year's Day, if you need to refer to my code before this, you can contact me directly, I can provide all the source code at any time.

When it comes to openid, many readers may have some knowledge about it. Yes, this is an open protocol to allow users to log on to all websites with an account and password, the purpose of this system is different, because the system is relatively selfish, hoping that all users can log on with their own accounts and passwords, openid is intended to allow all users to log on with an account and password on all websites. Of course, it is difficult to implement this function. Currently, it is not implemented, however, we can't help but admit that this is a very meaningful thing, and the system cannot help but support such account login.

For more information about openid, we suggest you visit the relevant website of openid. To be honest, this is a very promising project. If you are interested, you can check the related website of openid.

The implementation principle of openid is the same as that of this system, and Google's authsub, Yahoo's bbauth, and live account server, including oauth which I have not introduced yet, both use a trusted approach for users and Web applicationsProgramThe difference between establishing interactions is that openid must be open and compatible everywhere, so there are some other considerations. What are the specific considerations, I can understand the following points:

1. Use URL as the account. In this way, any website can be supported, and any website can provide openid.

2. in the URL provided by the user, you can specify the address of the openid server through the HTTP or HTML header, or even designate another openid address, this ensures that you can use your favorite website as your Logon account.

I don't know much about it than you do. I know that's all about it. For how to support openid login, although I have studied it for a long time, I finally come to a conclusion, use a public library, because openid is relatively complicated and it is still difficult to fully support it;

I am using the extremeswank DOTNET openid2.0 library, which is really useful, and soon I completed the support for openid, because my understanding of openid is actually not enough, therefore, it is not suitable for a long article on openid. Therefore, I simply provide the openid support code:

You must note that you only need to select the logon type for multiple types that I previously supported. For openid, you must first enter the Logon account (URL ), you can obtain the logon redirection address based on the URL address. Therefore, you must first enter an account to log on.

Because the logon interface varies according to the URL, the logon related code is not listed on this site this time. Only the implemented code is provided:

 

Openidserver. JS Code
1 Public   Class Openidserver: baseserver
2 {
3 Private   String Urlidentity = Null , Defaultnickname = Null ;
4 // The XML node in Web. config is used as the constructor parameter.
5 Public Openidserver (system. xml. xmlnode node)
6 : Base (Node)
7 {
8 For ( Int I =   0 ; I < Node. Attributes. Count; I ++ )
9 {
10 Switch (Node. attributes [I]. localname)
11 {
12 Case   " Urlidentity " : // If urlidentity is specified, users are not allowed to enter the account, and openid-type website logon is supported. For example, if it is set to Yahoo.com, users can directly support Yahoo login.
13 Urlidentity = Node. attributes [I]. value;
14 Break ;
15 Case   " Defaultnickname " : // Specify the default nickname
16 Defaultnickname = Node. attributes [I]. value;
17 Break ;
18 }
19 }
20 }
21 Public   Override   String Getloginurl () // Return logon address
22 {
23 Openidconsumer openid =   New Openidconsumer ( New Namevaluecollection (), Null , Null );
24
25 Simpleregistration SR =   New Simpleregistration (openid );
26 Sr. addrequiredfields (simpleregistrationfields. Nickname ); // Set the additional field list
27
28 Openid. returnurl =   This . Gethandleurl ();
29 Openid. Identity = Urlidentity ! = Null ? Urlidentity: httpcontext. Current. request [ " Openid_url " ];
30 Return Openid. beginauth ( False , False ); // Obtain and return the logon address
31 }
32 Public   Override   Void Parsehandle (httpcontext page) // Revolving content processing function
33 {
34 Openidconsumer openid =   New Openidconsumer (page. Request. querystring, Null , Null );
35 Switch (Openid. requestedmode)
36 {
37 Case Requestedmode. idresolution:
38 If (Openid. Validate ())
39 {
40 Openiduser user = Openid. retrieveuser ();
41 String Account = User. identity;
42 If (User. extensiondata. containskey (simpleregistrationfields. Email ))
43 {
44Account=User. extensiondata [simpleregistrationfields. Email];
45}
46 String Nickname; // Although an additional field type is set, it is not supported by the server. Therefore, you must determine whether the field exists.
47 If (User. extensiondata. containskey (simpleregistrationfields. Nickname ))
48 {
49Nickname=User. extensiondata [simpleregistrationfields. Nickname];
50}
51 Else
52 {
53Nickname=Defaultnickname! =Null?Defaultnickname: account;
54}
55 Accounthelper. setuserinfo (account, nickname, This . Name );
56 Accounthelper. returnopener ();
57 Page. response. End ();
58 }
59 Break ;
60 }
61 }
62 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.