我有一个MVC内部网站点,需要使用AD帐户进行身份验证.
我设置ADFS 3.0(Win Server 2012 R2)并按此设置ADFS信赖方信任.
这篇文章介绍了Ws-Federation OWIN组件,我想使用它.它提到了如何连接到Azure AD,但没有关于ADFS的任何内容.
我尝试设置配置属性"MetadataAddress"和"Wtrealm"以匹配我在ADFS中配置但在运行时我收到错误:
A default value for SignInAsAuthenticationType was not found in IAppBuilder Properties.
This can happen if your authentication middleware are added in the wrong order, or if one is missing.
Run Code Online (Sandbox Code Playgroud)
我正在寻找正确的方法删除此错误
我们有自己的OpenID Connect Provider.我们希望使用Owin中间件在身份验证请求中传递自定义查询参数.我们无法找到使用Microsoft.Owin.Security.OpenIdConnect程序集实现此方法的方法.甚至我们也找不到如何向Authentication Request添加标准请求参数(例如" login_hint parameter").
例如,Google有" login_hint "和" hd "参数(https://developers.google.com/accounts/docs/OAuth2Login#sendauthrequest),我们希望拥有几乎相同的参数.但我们甚至找不到如何使用Owin将这些参数发送给Google.试过这段代码:
var googleOptions = new GoogleOAuth2AuthenticationOptions()
{
ClientId = "...",
ClientSecret = "...",
};
app.UseGoogleAuthentication(googleOptions);
...
public ActionResult ExternalLogin(string provider)
{
var ctx = Request.GetOwinContext();
var properties = new AuthenticationProperties();
properties.Dictionary.Add("login_hint ", "myemail@gmail.com");
properties.Dictionary.Add("hd", "hd");
ctx.Authentication.Challenge(properties, provider);
return new HttpUnauthorizedResult();
}
Run Code Online (Sandbox Code Playgroud)
但是生成身份验证请求网址时将不使用" login_hint "和" hd "参数.
非常感谢任何帮助解决这个问题.
基于本教程http://www.asp.net/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server,我创建了一个授权服务器,一个资源服务器和一个MVC客户端.MVC客户端有一个Controller,它从资源服务器获取一些数据.资源服务器需要身份验证.MVC客户端从授权服务器获取授权代码,并将用户重定向到授权服务器以进行身份验证.最后,MVC客户端交换访问令牌的授权码以访问资源服务器.这是OAuth 2协议所描述的授权代码流.这很好用.
现在,我要求使MVC客户端的Controller本身需要身份验证.我找不到这方面的教程.
我补充道
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
Run Code Online (Sandbox Code Playgroud)
到我的Startup.Auth.cs.我假设,我需要设置选项以重定向到授权服务器.我还可以在选项上设置提供程序:
app.UseOAuthBearerAuthentication(new Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationOptions()
{
Provider = new OAuthBearerAuthenticationProvider()
});
Run Code Online (Sandbox Code Playgroud)
但我也坚持实施提供者的事件.有人能引导我朝正确的方向发展吗?或者是否有任何可能对我有帮助的教程?
我认为自己是OWIN的初级新手,在阅读了大量文档之后,我对比起之前的冲突概念感到困惑.我知道这些是多个问题,但我觉得回答这些问题将清除对OWIN以及如何最好地使用它的最基本的疑问.这是我的问题:

但是有错误:
如何查看请求并为中间件中的下一个组件修改它?
感谢您回答上述任何或所有这些问题.
我有通过命令行传入的参数
private static int Main(string[] args)
{
const string PORT = "12345" ;
var listeningUrl = $"http://localhost:{PORT}";
var builder = new WebHostBuilder()
.UseStartup<Startup>()
.UseKestrel()
.UseUrls(listeningUrl);
var host = builder.Build();
WriteLine($"Running on {PORT}");
host.Run();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
其中一个参数是日志输出目录.如何将这个值输入我的Startup班级,以便在收到请求时可以写到这个目录?
我想避免使用静态类.提供价值的服务是否是正确的方式?如果是这样,我如何将服务注入我的中间件?
我正在这个堆栈上构建自托管Web服务器:OWIN Nancy Web Api 2
我正在使用Katana的Microsoft.Owin.Security.Cookies进行类似形式的身份验证.我得到了Set-Cookie标头作为回应,但cookie没有保存,也没有被包含在下一个请求中.所以有什么问题?我做错了什么?
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationMode = AuthenticationMode.Active,
AuthenticationType = "GM",
CookieHttpOnly = true,
CookieSecure = CookieSecureOption.SameAsRequest,
CookiePath = "/",
CookieName = CookieAuthenticationDefaults.CookiePrefix + "GM",
CookieDomain = "localhost",
});
Run Code Online (Sandbox Code Playgroud)
var context = Request.GetOwinContext();
context.Authentication.SignIn(new AuthenticationProperties()
{
IsPersistent = true
},
new ClaimsIdentity(new[] {new Claim(ClaimsIdentity.DefaultNameClaimType, user.Login)}, "GM"));
context.Response.Headers.Add("Location", new []{ "/" });
return Request.CreateResponse(HttpStatusCode.Found);
Run Code Online (Sandbox Code Playgroud)
Cache-Control:no-cache
Content-Length:0
Date:Wed, 11 Sep 2013 11:11:23 GMT
Expires:-1
Location:/
Pragma:no-cache
Server:Microsoft-HTTPAPI/2.0
Set-Cookie:.AspNet.GM=AQAAANCMnd8BFdERjHoAwE_Cl-sBAAAABui2rBibE0yPXB0-v3C06gAAAAACAAAAAAAQZgAAAAEAACAAAAC1mQV3jGo_WAhMQ-hzsmzgkdbdCclWIAX-msbE0_12zQAAAAAOgAAAAAIAACAAAABuQjBg3EJIka151hvBgtlPGfQ2O_cwNI2VVh86dchTDXAAAAD21O9DnNk4yLU9eddVfY3bT9P1CEudNeLvwohkSTAQBP2onuIQfgl9F99Je5waPddckh2llD2kjftSMQPhzgE9vKm-_wE42hXhc9FIgfxpD5AdaeGatwpEcwDfGJJdpQnObX1pbjEFIXLVJxGm5qMUQAAAAC8AiFTaXmzrfRy4-jR6zqMmSKddzddmiBLGClAckWOy6W2YWdf50N2zhIj_MwN8-zi-B0tlv87pzAt-6RDZYZs; domain=localhost; path=/; expires=Wed, 25-Sep-2013 11:11:24 GMT; HttpOnly
Run Code Online (Sandbox Code Playgroud) 我试图了解OWIN和Katana ..当然,应用程序可以自托管,也可以托管在Nancy或非IIS上,这很酷.这个问题的原因是我们想要使用MVC5(VS 2013)创建一个Web应用程序,它将托管在Windows Azure的IIS上.
但是,我们收到了在mvc5应用程序中使用OWIN中间件组件/软件包的建议,以获得可插拔架构,性能等的好处.
我想了解如果我们在MVC5应用程序中使用OWIN中间件将会获得性能提升,该应用程序将托管在Windows Azure中的IIS上.我的应用程序是否会通过使用owin中间件包在IIS管道中跳过很多不必要的东西?当它在IIS上托管时,我可以通过在MVC5中使用OWIN获得任何其他好处吗?
我刚开始摆弄OWIN/Katana和MVC.NET 5.0.默认的Visual Studio 2013 ASP.NET Web应用程序/ MVC模板具有一个带有LogOut()操作的AccountController:
public ActionResult LogOff() {
AuthenticationManager.SignOut();
return RedirectToAction("Index", "Home");
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,这很好用.但是,当我更改响应状态代码时,例如:
Response.SetStatus(HttpStatusCode.SeeOther);
Run Code Online (Sandbox Code Playgroud)
... AuthenticationManager.SignOut()方法不再导致用户注销.这是为什么?
我尝试了不同的方法来设置响应的http状态代码,以及更改像"位置"这样的http标头,并且始终具有相同的结果 - 当执行LogOff()操作时,如果我进入回火状态,则用户不会注销随着回应.
我尝试不使用RedirectToAction(它显式实现302重定向 - 这是另一个故事),而不是返回ActionResult,但这没有任何区别 - 不是我真的希望它.
使用Fiddler我可以看出浏览器看起来的响应看起来很好,没有任何意外.
我也尝试在工作中查看OWIN中间件的源代码,但我仍然不熟悉该架构,我找不到我能掌握的答案.我需要你的帮助来解决这个问题,所以提前谢谢你!
我正在使用带有Asp.Net Identity 2的Web Api 2.1.我试图在我的ApiController的构造函数上获取经过身份验证的用户(我使用AutoFac来注入我的依赖项),但是在调用构造函数时,User显示为未经过身份验证.
我试图获取用户,以便我可以为任何数据库写操作生成审计信息.
我正在做的一些事情可以帮助诊断:
我只 app.UseOAuthBearerTokens使用Asp.Net Identity 2进行身份验证.这意味着app.UseCookieAuthentication(new CookieAuthenticationOptions())当您使用Asp创建新的Web Api 2.1项目时,我删除了默认启用的功能. .Net Identity 2.
在里面WebApiConfig我正在注入我的存储库:
builder.RegisterType<ValueRepository>().As<IValueRepository>().InstancePerRequest();
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
[RoutePrefix("api/values")]
public class ValuesController : ApiController
{
private IValueRepository valueRepository;
public ValuesController(IValueRepository repo)
{
valueRepository = repo;
// I would need the User information here to pass it to my repository
// something like this:
valueRepository.SetUser(User);
}
protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
// User is not avaliable here either...
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我检查构造函数上的User对象,这就是我得到的: …
我正在制作一个位于ASP.Net WebAPI之上的SPA.我正在等待使用HTML5历史记录而不是#/历史路由,但是这会给深度链接带来问题,我需要确保/并且/foo/bar都返回相同的HTML文件(我的JS将呈现SPA的正确部分).
如何让OWIN/Katana为多个不同的网址返回相同的HTML文件?