我刚开始摆弄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中间件的源代码,但我仍然不熟悉该架构,我找不到我能掌握的答案.我需要你的帮助来解决这个问题,所以提前谢谢你!
我正在尝试为我的组织实施OpenID Connect规范.我在测试依赖方应用程序中使用Microsoft的OpenID Connect的OWIN实现来验证我的协议实现.
我已经公开了以下元数据文档:
{
"issuer": "https://acs.contoso.com/",
"authorization_endpoint": "http://localhost:53615/oauth2/auth",
"token_endpoint": "http://localhost:53615/oauth2/token",
"userinfo_endpoint": "http://localhost:53615/connect/userinfo",
"jwks_uri": "http://localhost:53615/connect/keys",
"ui_locales_supported": [
"en-GB"
]
}
Run Code Online (Sandbox Code Playgroud)
签名密钥作为此文档公开:
{
"keys": [
{
"n": "xpXxl3M-YkZlzQJdArO1TfOGT2no-UL4dbZ7WuSCNIsSfyGDaqUXjMMHNyq9yD3vp-NCyk8kmn7d5XqHufnceXJM8q4xTrhN3lvywdBSbR-dwXsA-B-MJVgfiK0d_z-mxP9ew2Hj9-KkWbWCzsswlWp3gZ4mB4RGutB1IRSzXVIbvZ-MtKUb6XUDU4LDb_c1xCEXWZxhR-o1a1dLfObH2hHJ-w5y6odGlKtOFx4i4h0u7-Oj5R6k5b2YXEHM0IuYeN0u0sQvrTecokntGzPrvhnKy69I7Z_az5rC5kgloh25D9lTbe4vcRU7FXlYCFYDZsT0_IkGIXRi7brOS4f1ow",
"e": "AQAB",
"kty": "RSA",
"use": "sig",
"alg": "RS256",
"kid": "F8A59280B3D13777CC7541B3218480984F421450"
}
]
}
Run Code Online (Sandbox Code Playgroud)
使用JwtSecurityToken
类及其关联的处理程序生成标识令牌X509SigningCredentials
.此代码表示如何构造令牌并将其作为响应数据的参数返回给调用系统.
var credentials = new X509SigningCredentials(cert); // My certificate.
var issuedTime = DateTime.UtcNow;
var expiresTime = issuedTime.AddMinutes(5);
var epoch = new DateTime(1970, 01, 01, 0, 0, 0);
var claims = new[]
{
new Claim("sub", Guid.NewGuid().ToString()),
new …
Run Code Online (Sandbox Code Playgroud) 我需要构建一个Owin中间件对象,但不是在Startup
类中.我需要在我的代码中的任何其他地方构建它,所以我需要AppBuilder
对应用程序实例的引用.有没有办法从其他地方获得?
我正在根据Katana项目中的其他示例为OpenID Connect授权代码流编写自己的OWIN中间件.
作为其中的一部分,我必须构造一些URI,例如重定向URI和返回URL.
Katana中的其他示例通过连接当前请求中的部分来完成此操作,例如在CookieAuthenticationHandler中
loginUri =
Request.Scheme +
Uri.SchemeDelimiter +
Request.Host +
Request.PathBase +
Options.LoginPath +
new QueryString(Options.ReturnUrlParameter, currentUri);
Run Code Online (Sandbox Code Playgroud)
我的问题是什么规则管理两个路径属性中的最终结果:
OwinContext.Request.Path
OwinContext.Request.PathBase
Run Code Online (Sandbox Code Playgroud)
我已经尝试检查这些属性,因为请求通过下面管道中的不同处理程序,请求:
"https://localhost/Client/login" // Where Client is a virtual directory in IIS
Run Code Online (Sandbox Code Playgroud)
结果:
因此,如果不知道如何填充这些值的"规则",然后更改,则很难使用它们构造URI.如果有人能解释,将不胜感激.
我的配置的摘录是:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
LoginPath = new PathString("/Login")
});
app.UseQuillCodeFlowAuthentication(new QuillCodeFlowOptions());
app.Map("/login", map =>
{
map.Run(async ctx =>
{
if (ctx.Authentication.User == null ||
!ctx.Authentication.User.Identity.IsAuthenticated)
{
var authenticationProperties = new AuthenticationProperties();
[...] …
Run Code Online (Sandbox Code Playgroud) 我在WebApi Katana应用程序中使用路由.我有以下两个路由映射,工作正常.我的问题是,我可以使用可选参数将它们组合成单个路径映射吗?我看不到明显的方法来保持所需的功能.我是新手,可能错过了我帮助我实现这一目标的技巧.如果路线必须保持这种方式,那么这不是问题.
config.Routes.MapHttpRoute(
name: "UnRegister",
routeTemplate: "api/services/{serviceName}/{location}",
defaults: new {controller = "MyController", location = RouteParameter.Optional});
config.Routes.MapHttpRoute(
name: "UnRegister2",
routeTemplate: "api/services/{serviceName}/{instanceId}",
defaults: new { controller = "MyController" });
Run Code Online (Sandbox Code Playgroud)
所需的功能是通过提供以下详细信息来注销服务:
Servicename
Servicename and location
Servicename and instanceId
Run Code Online (Sandbox Code Playgroud) 我配置了Identity Server:
public void Configuration(IAppBuilder app)
{
var factory = new IdentityServerServiceFactory().UseInMemoryClients(new Client[] {
new Client()
{
ClientName = "MyClient",
ClientId = "MyClientId",
Enabled = true,
Flow = Flows.Implicit,
RedirectUris = new List<string> { "MyClientServer/callback" },
};
});
}
Run Code Online (Sandbox Code Playgroud)
和客户端服务器:
public void Configuration(IAppBuilder app)
{
var cookieOptions = new CookieAuthenticationOptions();
cookieOptions.AuthenticationType = "Cookies";
app.UseCookieAuthentication(cookieOptions);
var authenticationOptions = new OpenIdConnectAuthenticationOptions() {
Authority = "https://MyIdentityServer/core",
ClientId = "MyClientId",
SignInAsAuthenticationType = "Cookies",
UseTokenLifetime = true,
RedirectUri = "MyClientServer/callback"
});
app.UseOpenIdConnectAuthentication(authenticationOptions);
}
Run Code Online (Sandbox Code Playgroud)
当用户使用"记住我"选项登录时,身份cookie已过期日期:
idsvr.session …
Run Code Online (Sandbox Code Playgroud) cookies session-cookies katana asp.net-identity identityserver3
我使用OWIN OAuth 2来实现我的授权服务器提供程序.现在,我想实现令牌撤销(当我的客户端应用程序想要注销时).
任何人都可以帮助我并告诉如何在OWIN KATANA OAuth中实施令牌撤销2.是否有一些良好的做法?
遵循本指南,使用Owin上的MVC 5进行外部身份验证 - 使用owinkatana的外部登录提供程序.
我已将以下内容添加到我的Owin Nancy应用程序中
Startup.cs -
app.Properties["Microsoft.Owin.Security.Constants.DefaultSignInAsAuthenticationType"] = "ExternalCookie";
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "ExternalCookie",
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive,
});
app.UseTwitterAuthentication(new TwitterAuthenticationOptions
{
ConsumerKey = "mykey",
ConsumerSecret = "mypass"
});
Run Code Online (Sandbox Code Playgroud)
LoginModule.cs(nancy模块)
Post["ExternalLogin"] = _ =>
{
var provider = Request.Form.name;
var auth = Context.GetAuthenticationManager();
auth.Challenge(new AuthenticationProperties
{
RedirectUri = String.Format("/?provder={0}", provider)
}, provider);
return HttpStatusCode.Unauthorized;
};
Run Code Online (Sandbox Code Playgroud)
现在在挑战点,没有任何事情发生.它只显示一个空白页面,其中包含重定向的Url.我已经确认我可以按照MVC中的示例来使用它.有谁知道这部分的正确南希代码?
如何配置可从其他主机访问的owin Web服务器.所有示例都配置为localhost.我可能不知道URL是什么.(IP地址/主机名)
码:
class Program
{
static string url = "http://localhost:9080";
static void Main(string[] args)
{
using (WebApp.Start<Startup>(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个在OWIN进程中托管的示例Web API(自托管,而不是在IIS中).我在我的控制器中获得了一个JWT令牌,我希望能够在应用程序的另一部分中进行检索,这是一个实现NserviceBus IMutateOutgoingTransportMessages的类.在我的其他Web应用程序POC(在IIS中托管)中,我使用了一个简单的会话变量,它工作得很好.但我想知道在我的新OWIN自托管环境中最好的方法是什么?静态类中的静态属性?
katana ×10
owin ×8
c# ×4
asp.net ×2
asp.net-mvc ×2
cookies ×1
jwt ×1
nancy ×1
oauth ×1
rest ×1
self-hosting ×1
web-services ×1