第三方登录之GitHub篇

 

 %@ page language="c#" autoeventwireup="true" codebehind="login.aspx.cs" inherits="githublogin.login" % 
 !doctype html 
 html xmlns="http://www.w3.org/1999/xhtml" 
 head runat="server" 
 meta http-equiv="content-type" content="text/html; charset=utf-8"/ 
 title /title 
 /head 
 body 
 form id="form1" runat="server" 
 div 
 a href="https://github.com/login/oauth/authorize?client_id=xxxxxxxxxxxxxxxxxxxxxx state=state redirect_uri=http://www.kudsu.xyz/" github登录 /a 
 /div 
 /form 
 /body 
 /html 
using newtonsoft.json;
using newtonsoft.json.linq;
using system;
using system.collections.generic;
using system.io;
using system.linq;
using system.net;
using system.net.http;
using system.text;
using system.threading.tasks;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
namespace githublogin
 public partial class login : system.web.ui.page
 protected void page_load
 if 
 string code = request.querystring["code"] == null || request.querystring["code"].tostring == "" ? "" : request.querystring["code"].tostring;
 if 
 //第二步,获取token
 string tokenjson = loadurlstring;
 jobject jo = jsonconvert.deserializeobject;
 tokenjson = jo["access_token"].tostring;
 //第三步,获取github用户信息
 string userjson = loadurlstring;
 //把github用户信息输出到页面上
 response.write;
 /// summary 
 /// 请求url
 /// /summary 
 /// param name="url" 地址 /param 
 /// param name="getpost" post、get /param 
 /// returns /returns 
 private string loadurlstring
 system.net.servicepointmanager.securityprotocol = securityprotocoltype.tls12;
 httpwebrequest request1 = webrequest.create;
 request1.method = getpost;
 request1.contenttype = "application/json";
 request1.accept = "application/json";
 request1.headers.add;
 request1.useragent = "mozilla/5.0  gecko/20100101 firefox/12.0";
 return new streamreaderrequest1.getresponse).getresponsestream, encoding.utf8).readtoend;
}

   亲,如果可以,给个星星~

 

Copyright © 2018 乐橙app下载乐橙app下载-乐橙lc8 All Rights Reserved