贵阳汽车网

当前的位置是:主页 >> 车险

木纹基于DotNetOpenAuth的OAu

时间:2020-09-20 来源网站:贵阳汽车网

1. 场景

根据OAuth 2.0规范,该场景发生于下面的流程图中的(D)(E)节点,根据已经得到的authorization code获取access token。

2. 实现环境

DotNetOpthAuth v5.0.0-alpha3, MVC 5, .NET Framework 4.5.1。

2. 主要实现示例代码

2.1. Authorization Server实现代码

2.1.1. MVC Controller实现代码

using sks; using c; using enAuth; using uth2; using ssaging; namespace ntrollers { public class OAuthController : Controller { public async TaskActionResult Token() { var authServer = new AuthorizationServer(new AuthorizationServerHost()); var response = await ndleTokenRequestAsync(Request); return ActionResult(); } } }

uthorizationServerHost接口实现

需要实现IsAuthorizationValid避免守城方快速组成很强力的阵营。盘龙柱摧毁之后与CreateAccessToken这两个方法,实现代码如下:

public class AuthorizationServerHost : IAuthorizationServerHost { public bool IsAuthorizationValid(IAuthorizationDescription authorization) { return ientIdentifier == webclientdemo ClientIdentifier.; } public AccessTokenResult CreateAccessToken(IAccessTokenRequest accessTokenRequestMessage) { var accessToken = new AuthorizationServerAccessToken { Lifetime = omHours(10), SymmetricKeyStore = yptoKeyStore, }; var result = new AccessTokenResult(accessToken); return result; } }

2.2 Client实现代码

namespace ntrollers { public class OAuthController : Controller { private static readonly string CLIENT_ID = webclientdemo; public async TaskActionResult Redirect(string code) { var httpClient = new HttpClient(); var queryDict = new Dictionarystring, string { {grant_type, authorization_code}, {code, code}, {redirect_uri, heme + :// + st + solutePath}, {client_id, CLIENT_ID}, {client_secret, webclientdemosecret} }; var httpContent = new FormUrlEncodedContent(queryDict); var response = await stAsync(heme + :// httpContent); return Content(await adAsStringAsync()); } } }

考虑到跨平台访问的方便性,未使用bServerClient。

3. 参考资料:

DotNetOpenAuth源代码: OAuth 2.0规范:


辽宁白癜风医院
2岁小孩不爱吃饭怎么办
金昌白癜风专业治疗医院