【发布时间】:2016-05-21 10:47:56
【问题描述】:
我有一个 .NET 4.0 应用程序,我需要添加第三层的 OAuth2 身份验证。而且我有点困惑(很难找到 .NET 4.0 的示例和文档)。
我可以将 Microsoft.AspNet.Membership.OpenAuth (OAuth 2.0) 与 Asp.net 4.0 (.NET 4.0) 一起使用吗?
我的另一个选择是使用 DotNetOpenAuth,但我很难找到一个在 .NET 4.0 中使用 Callback for Webforms 的示例。
据我了解,我应该有一个身份验证页面(登录页面):
var medOK = new WebServerClient(GetAuthServerDescription(), clientIdentifier: "some client id");
medOK.ClientCredentialApplicator = ClientCredentialApplicator.PostParameter("some secret code");
// CallBack
var state = new AuthorizationState();
var uri = Request.Url.AbsoluteUri;
uri = RemoveQueryStringFromUri(uri);
state.Callback = new Uri(uri);
var accessTokenResponse = medOK.ProcessUserAuthorization();
if (accessTokenResponse != null){
//If you have accesstoek then do something
} else if (this.AccessToken == null) {
// If we don't yet have access, immediately request it.
medOK.PrepareRequestUserAuthorization(state);
medOK.RequestUserAuthorization();
}
还有一个回调页面(比如说一个 ashx 页面):
var medOK = new WebServerClient(GetAuthServerDescription(), clientIdentifier: "some client id");
medOK.ClientCredentialApplicator = ClientCredentialApplicator.PostParameter("some secret code");
var response = medOK.GetClientAccessToken();
// Then I get claims
有意义吗? (我尽量简洁,不写所有我试过的,但如果需要我可以提供更多信息)
【问题讨论】:
标签: c# .net-4.0 oauth-2.0 owin dotnetopenauth