问题描述
作为一个有点断章取义,我正在开发,只有在这个阶段通过微软的OWIN实现使用基于OAuth的认证,对于Facebook和谷歌的ASP.NET MVC 5应用程序。目前(截至V3.0.0中,混帐提交4932c2f),在 FacebookAuthenticationOptions
和 GoogleOAuth2AuthenticationOptions
不提供任何财产在登录时强制Facebook的谷歌也分别重新验证用户(通过附加相应的查询字符串参数)。
As a bit of context, I'm developing an ASP.NET MVC 5 application that uses OAuth-based authentication via Microsoft's OWIN implementation, for Facebook and Google only at this stage. Currently (as of v3.0.0, git-commit 4932c2f), the FacebookAuthenticationOptions
and GoogleOAuth2AuthenticationOptions
don't provide any property to force Facebook nor Google respectively to reauthenticate users (via appending the appropriate query string parameters) when signing in.
起初,我开始重写以下类:
Initially, I set out to override the following classes:
-
FacebookAuthenticationOptions
-
GoogleOAuth2AuthenticationOptions
-
FacebookAuthenticationHandler
(特别是AuthenticateCoreAsync()
) -
GoogleOAuth2AuthenticationHandler
(特别是AuthenticateCoreAsync()
)
FacebookAuthenticationOptions
GoogleOAuth2AuthenticationOptions
FacebookAuthenticationHandler
(specificallyAuthenticateCoreAsync()
)GoogleOAuth2AuthenticationHandler
(specificallyAuthenticateCoreAsync()
)
但发现〜的AuthenticationHandler
类被标记为内部
。
所以我把源的武士刀项目的副本(),并相应修改源。
So I pulled a copy of the source for the Katana project (http://katanaproject.codeplex.com/) and modified the source accordingly.
编译之后,我发现有一些必要的,以使用这些更新组件( Microsoft.Owin.Security.Facebook 和 Microsoft.Owin.Security.Google )
After compiling, I found that there are several dependencies that needed updating in order to use these updated assemblies (Microsoft.Owin.Security.Facebook and Microsoft.Owin.Security.Google) in the MVC project:
- Microsoft.Owin
- Microsoft.Owin.Security
- Microsoft.Owin.Security.Cookies
- Microsoft.Owin.Security.OAuth
- Microsoft.Owin.Host.SystemWeb
这是替换现有的项目引用到3.0.0版本,并更新这些在web.config中完成的。好消息:该项目成功编译
This was done by replacing the existing project references to the 3.0.0 versions and updating those in web.config. Good news: the project compiles successfully.
在调试时,我就收到启动一个例外:
In debugging, I received an exception on startup:
型System.IO.FileLoadException的异常出现在[的MVC Web组件] .dll文件,但在用户code没有处理
其他信息:无法加载文件或程序集Microsoft.Owin.Security,版本= 3.0.0.0,文化=中性公钥= 31bf3856ad364e35或它的一个依赖。找到的程序集清单定义不匹配程序集引用。 (异常来自HRESULT:0x80131040)
Additional information: Could not load file or assembly 'Microsoft.Owin.Security, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
基本的异常表明 Microsoft.AspNet.Identity.Owin 试图装入V2.1.0的 Microsoft.Owin.Security 当调用 app.UseExternalSignInCookie()
从 Startup.ConfigureAuth(IAppBuilder应用)
在Startup.Auth.cs。
The underlying exception indicated that Microsoft.AspNet.Identity.Owin was trying to load v2.1.0 of Microsoft.Owin.Security when calling app.UseExternalSignInCookie()
from Startup.ConfigureAuth(IAppBuilder app)
in Startup.Auth.cs.
不幸的组件(和它的其他的依赖, Microsoft.AspNet.Identity.Owin )不是项目武士刀解决方案的一部分,我不能在网上找到这些组件的任何可访问的资源库
Unfortunately that assembly (and its other dependency, Microsoft.AspNet.Identity.Owin) aren't part of the Project Katana solution, and I can't find any accessible repository for these assemblies online.
是在 Microsoft.AspNet.Identity 组件开源,像武士刀的项目?
有没有办法来愚弄那些组件使用引用V3.0.0组件,而不是V2.1.0?在 / bin中
文件夹中包含了3.0.0版本的Owin组件。
我已经升级了的NuGet包的 Microsoft.AspNet.Identity.Owin ,这仍然是一个问题。
I've upgraded the NuGet packages for Microsoft.AspNet.Identity.Owin, and this is still an issue.
如何解决这个问题的任何想法?
Any ideas on how to resolve this issue?
推荐答案
我发现,虽然 FacebookAuthenticationHandler
标记为内部
,它的抽象基类的AuthenticationHandler< TOptions>
幸运的是公共
。最后,我把 FacebookAuthenticationHandler
的修改版本从卡塔纳项目源,更名并包括在我自己的解决方案,因此,它仍然采用2.1库和没有按'T引起其他的NuGet依赖的问题。
I've found that while FacebookAuthenticationHandler
is marked as internal
, its abstract base class AuthenticationHandler<TOptions>
is fortunately public
. In the end, I took the modified version of FacebookAuthenticationHandler
from the Katana project source, renamed it and included it in my own solution, so that it still uses the 2.1 libraries and doesn't cause problems with the other NuGet dependencies.
同样,对于 GoogleOAuth2AuthenticationHandler
。
因此,使用Facebook的例子中,我有以下类定义在我的MVC项目:
So, using the Facebook example, I have the following class definitions in my MVC project:
// Overridden to add additional property 'ForceReauthentication'
public class FacebookOAuth2ExtendedOptions : FacebookAuthenticationOptions
...
// Reimplemented v2.1 source with modified method 'ApplyResponseChallengeAsync'
public class FacebookOAuth2CustomHandler : AuthenticationHandler<FacebookOAuth2ExtendedOptions>
...
// Reimplemented v2.1 source, modified to use 'FacebookOAuth2CustomHandler '
public class FacebookOAuth2CustomMiddleware : AuthenticationMiddleware<FacebookOAuth2ExtendedOptions>
...
最后,在启动
类( App_Start / Startup.Auth.cs ),我用注册我的自定义中间件类认证:
Finally in the Startup
class (App_Start/Startup.Auth.cs), I register the authentication using my custom middleware classes:
public void ConfigureAuth(IAppBuilder app)
{
...
var fbOptions = new FacebookOAuth2ExtendedOptions()
{
AppId = facebookAppKey,
AppSecret = facebookAppSecret,
ForceReauthentication = true
};
app.Use(typeof(FacebookOAuth2CustomMiddleware), app, fbOptions);
...
}
希望这有助于其他类似问题。
Hope this helps others with similar issues.
这篇关于ASP.NET MVC试图加载Owin装配的旧版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!