Use devdefined. oauth to implement Sina login and obtain user information

Source: Internet
Author: User
Tags oauth

 

 
Protected void page_load (Object sender, eventargs e) {If (! Ispostback) {ABC () ;}} private void ABC () {If (session ["oasession1"] = NULL) return; if (request ["oauth_verifier"] = NULL) return; oauthsession session = (oauthsession) session ["oasession1"]; var oauthverifier = request ["oauth_verifier"]; string userid = "";
Session. responsebodyaction = body => {userid = RegEx. Match (body, "user_id = (. *)"). Groups [1]. value ;};
Itoken accesstoken = session. exchangerequesttokenforaccesstoken (itoken) session ["requesttoken"], oauthverifier); string STR = session. request (). get (). forurl ("http://api.t.sina.com.cn/users/show/" + userid + ". JSON? Source = sina application key "). tostring (); Using (jsonreader = new jsontextreader (New stringreader (STR) {While (jsonreader. read () {response. write (jsonreader. value + "<br/>") ;}} protected void button#click (Object sender, eventargs e) {string requesturl = "http://api.t.sina.com.cn/oauth/request_token"; string userauthorizeurl = "http://api.t.sina.com.cn/oauth/authorize "; string accessurl = "http://api.t.sina.com.cn/oauth/access_token"; string callbackurl = "http: // localhost: 2354/website1/default. aspx "; var context = new devdefined. oauth. consumer. oauthconsumercontext {consumerkey = "Sina application key", consumersecret = "Sina application scret", signaturemethod = signaturemethod. hmacsha1}; // If (session ["oasession1"] = NULL) {session ["oasession1"] = new oauthsession (context, requesturl, userauthorizeurl, accessurl ); session ["requesttoken"] = (oauthsession) session ["oasession1"]). getrequesttoken (); string anthorurl = (oauthsession) session ["oasession1"]). getuserauthorizationurlfortoken (itoken) session ["requesttoken"], callbackurl); response. redirect (anthorurl );}}

 

DownloadCodeIn session. responsebodyaction = body => {userid = RegEx. Match (body, "user_id = (. *)"). Groups [1]. value;}; move

Itoken accesstoken = session. exchangerequesttokenforaccesstoken (itoken) session ["requesttoken"], oauthverifier); the last line.

Code download: http://download.csdn.net/detail/lem12/3664338

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.