|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
有理由相信是能提供更出色的性能。很多平台无法支持复杂的编译器,因此需要二次编译来减少本地编译器的复杂度。当然可能做不到net网页编程编译器那么简易。1.场景
依据OAuth2.0标准,该场景产生于上面的流程图中的(D)(E)节点,依据已失掉的authorizationcode猎取accesstoken。
2.完成情况
DotNetOpthAuthv5.0.0-alpha3,ASP.NETMVC5,.NETFramework4.5.1。
2.次要完成示例代码
2.1.AuthorizationServer完成代码
2.1.1.ASP.NETMVCController完成代码
- usingSystem.Threading.Tasks;usingSystem.Web.Mvc;usingCNBlogs.Open.Domain.Entities.OpenAuth;usingDotNetOpenAuth.OAuth2;usingDotNetOpenAuth.Messaging;namespaceCNBlogs.Open.Web.Controllers{publicclassOAuthController:Controller{publicasyncTask<ActionResult>Token(){varauthServer=newAuthorizationServer(newAuthorizationServerHost());varresponse=awaitauthServer.HandleTokenRequestAsync(Request);returnresponse.AsActionResult();}}}
复制代码
2.1.2.IAuthorizationServerHost接话柄现
必要完成IsAuthorizationValid与CreateAccessToken这两个办法,完成代码以下:
- publicclassAuthorizationServerHost:IAuthorizationServerHost{publicboolIsAuthorizationValid(IAuthorizationDescriptionauthorization){returnauthorization.ClientIdentifier=="webclientdemo"&&ClientIdentifier.;}publicAccessTokenResultCreateAccessToken(IAccessTokenRequestaccessTokenRequestMessage){varaccessToken=newAuthorizationServerAccessToken{Lifetime=TimeSpan.FromHours(10),SymmetricKeyStore=this.CryptoKeyStore,};varresult=newAccessTokenResult(accessToken);returnresult;}}
复制代码
2.2Client完成代码
- namespaceOAuthWebClient.Controllers{publicclassOAuthController:Controller{privatestaticreadonlystringCLIENT_ID="webclientdemo";publicasyncTask<ActionResult>Redirect(stringcode){varhttpClient=newHttpClient();varqueryDict=newDictionary<string,string>{{"grant_type","authorization_code"},{"code",code},{"redirect_uri",Request.Url.Scheme+"://"+Request.Url.Host+Request.Url.AbsolutePath},{"client_id",CLIENT_ID},{"client_secret","webclientdemosecret"}};varhttpContent=newFormUrlEncodedContent(queryDict);varresponse=awaithttpClient.PostAsync(Request.Url.Scheme+"://open.cnblogs.com/oauth/token",httpContent);returnContent(awaitresponse.Content.ReadAsStringAsync());}}}
复制代码
思索到跨平台会见的便利性,未利用DotNetOpenAuth.OAuth2.WebServerClient。
3.参考材料:
- DotNetOpenAuth源代码:https://github.com/DotNetOpenAuth/DotNetOpenAuth
- OAuth2.0标准:http://tools.ietf.org/html/rfc6749
因为各系统的API不同,代码调用API编写程序就会遇到很多不兼容的地方,比如net网页编程改写后的Serv-U就不能在手机上执行,手机的游戏也不能直接在微机上执行。 |
|