jen*_*ens 37 c# asp.net asp.net-mvc dotnetopenauth oauth-2.0
我一直在使用DotNetOpenAuth工作.首先我们使用5.0.0-alpha1,但我们切换到v4.0.30319,因为我们找不到导致我们问题的原因.
我们在Visual Studio 2013的.NET 4.5.1建立一个C#的Web API项目RC与MVC 5 RC我们已经实施了IAuthorizationServerHost,INonceStore和ICryptoKeyStore.
我们遇到的问题是以下情况:
public class TokensController : Controller
{
private readonly AuthorizationServer authorizationServer = new AuthorizationServer(new MyAuthorizationServer());
/// <summary>
/// This action will handle all token requests.
/// </summary>
/// <returns>The action result that will output the token response.</returns>
[HttpPost]
public ActionResult Index()
{
var outgoingWebResponse = this.authorizationServer.HandleTokenRequest(this.Request);
return outgoingWebResponse.AsActionResult();
}
}
Run Code Online (Sandbox Code Playgroud)
return outgoingWebResponse.AsActionResult();与起源的方法DotNetOpenAuth.Messaging和MessagingUtilities静态类.该DotNetOpenAuth.Core(包含此代码)引用MVC 4.0和HttpResponseMessageActionResult类从继承ActionResult.
这意味着当前版本的DotNetOpenAuth与MVC 5不兼容.编译并尝试运行它只会出现500个错误.
有没有人有任何想法如何轻松修复(或可能不)?
我没注意到DotNetOpenAuth Nuget包写了我的5.0包.因此,重新安装包并再次添加assemblyBinding后:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
Run Code Online (Sandbox Code Playgroud)
这让我们更进一步.现在错误归结为:
尝试通过安全透明方法'DotNetOpenAuth.Messaging.MessagingUtilities.AsActionResult(DotNetOpenAuth.Messaging.OutgoingWebResponse)'来访问安全关键类型'System.Web.Mvc.ActionResult'失败.
And*_*ott 50
修复可用.
安装NuGet包DotNetOpenAuth.Mvc5并更改AsActionResult()to的所有用途AsActionResultMvc5()
经过进一步调试并在GitHub上与DotNetOpenAuth的人们交谈后,https://github.com/DotNetOpenAuth/DotNetOpenAuth/issues/307得出结论,MVC 5有一个新的安全模型.
因此绑定重定向是不够的.直到更进一步,有两种选择:
1)抓取DotNetOpenAuth源代码并从所有项目中删除[assembly:AllowPartiallyTrustedCallers].重新编译和成员以禁用强名称验证sn -Vr*.此代码无法在Medium Trust环境中运行.
2)抓取DotNetOpenAuth源代码并针对MVC 5重新编译它.
根据对GitHub的讨论,最好的未来解决方案是将所有相关的MVC内容移出到单独的程序集中.
| 归档时间: |
|
| 查看次数: |
6492 次 |
| 最近记录: |