我下载了katana项目,想在沙箱项目中尝试客户端/服务器.
我为OAuthValidateClientAuthenticationContext遇到了一个问题:
public bool TryGetFormCredentials(out string clientId, out string clientSecret)
{
clientId = Parameters.Get(Constants.Parameters.ClientId);
if (!String.IsNullOrEmpty(clientId))
{
clientSecret = Parameters.Get(Constants.Parameters.ClientSecret);
ClientId = clientId;
return true;
}
clientId = null;
clientSecret = null;
return false;
}
Run Code Online (Sandbox Code Playgroud)
clientSecret为null,因此以下内容未验证客户端.
private Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string clientId;
string clientSecret;
if (context.TryGetBasicCredentials(out clientId, out clientSecret) ||
context.TryGetFormCredentials(out clientId, out clientSecret))
{
if (clientId == "123456" && clientSecret == "abcdef")
{
context.Validated();
}
else if (context.ClientId == "7890ab" && clientSecret == "7890ab")
{
context.Validated();
}
} …Run Code Online (Sandbox Code Playgroud) 我有一些时间做研发,并且到目前为止一直在玩OWIN.
我想为所有数据交互运行一个OWIN WebAPI服务,并使用一个单独的Web前端SPA项目来使用angular.
所有代码都是从各种随机博客帖子中无耻地窃取的,它只是为了掌握这种"新技术".
启动
public class Startup
{
public void Configuration(IAppBuilder app)
{
#if DEBUG
app.UseErrorPage();
#endif
app.UseWelcomePage("/");
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
app.UseWebApi(config);
app.Run(context =>
{
if (context.Request.Path.ToString() == "/fail")
{
throw new Exception("Random exception");
}
context.Response.ContentType = "text/plain";
return context.Response.WriteAsync("App Init");
});
}
}
Run Code Online (Sandbox Code Playgroud)
AccountsController
public class AccountsController : ApiController
{
// GET api/<controller>/5
public string Get(int id) …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现登录到我的OWIN自托管解决方案.
我的MiddleWare班级如下:
public class HostingMiddleware : OwinMiddleware
{
private readonly ILogger _logger;
public HostingMiddleware(OwinMiddleware next, IAppBuilder builder)
: base(next)
{
_logger = builder.CreateLogger<HostingMiddleware>();
}
public override Task Invoke(IOwinContext context)
{
_logger.WriteVerbose(string.Format("{0} {1}: {2}"));
context.Response.Headers.Add("Content-Type", new[]
{
"text/plain"
});
return Invoke(context);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我在Startup课堂上使用它.
public class Startup
{
public void Configuration(IAppBuilder builder)
{
// Initialize the configuration for Web API self-host.
HttpConfiguration config = new HttpConfiguration();
// Map the default Web API HTTP Route
config.Routes.MapHttpRoute(
name: "DefaultApi", …Run Code Online (Sandbox Code Playgroud) 我将我的应用程序从mvc4升级到mvc5.我在我的应用程序中使用实体框架代码第一种方法.我对OWIN和Katana感到困惑.我如何在我的web mvc5应用程序中实现这些概念.请指导我.
谢谢
当我使用 Microsoft.Owin.StaticFiles 时,如何在将响应发送到客户端之前修改响应?
FileServerOptions options = new FileServerOptions();
options.FileSystem = new Microsoft.Owin.FileSystems.PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, "Content/"));
options.DefaultFilesOptions.DefaultFileNames = new string[] { "index.htm", "index.html" };
options.StaticFileOptions.OnPrepareResponse = (r) =>
{
r.OwinContext.Response.WriteAsync("test");
};
options.EnableDefaultFiles = true;
app.UseFileServer(options);
Run Code Online (Sandbox Code Playgroud)
“测试”永远不会写入响应。我尝试使用另一个中间件,直到执行 StaticFiles 中间件:
app.Use((ctx, next) =>
{
return next().ContinueWith(task =>
{
return ctx.Response.WriteAsync("Hello World!");
});
});
FileServerOptions options = new FileServerOptions();
options.FileSystem = new Microsoft.Owin.FileSystems.PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, "Content/"));
options.DefaultFilesOptions.DefaultFileNames = new string[] { "index.htm", "index.html" };
options.EnableDefaultFiles = true;
app.UseFileServer(options);
Run Code Online (Sandbox Code Playgroud)
但这没有用。如何修改响应?
我正在努力熟悉OWIN,有很多让我感到困惑的事情.例如,在部分startup.cs类中,我通过注册上下文回调
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
Run Code Online (Sandbox Code Playgroud)
有什么不同?为什么我们需要这种通用方法?
我可以得到这样的上下文:
context.Get<ApplicationDbContext>())
context.GetUserManager<ApplicationUserManager>()
Run Code Online (Sandbox Code Playgroud)
Get和GetUserManager方法有什么区别?为什么我不能只调用context.Get for ApplicationUserManager?
有人可以解释如何使用新的Owin WS-Federation插件实现滑动过期吗?
在客户端,在WS-Fedeartion 配置中,我看到有一些事件,如:
Notifications = new WsFederationAuthenticationNotifications
{
SecurityTokenReceived = ...,
AuthenticationFailed = ...,
RedirectToIdentityProvider = ...,
MessageReceived = ...,
SecurityTokenValidated = ....
},
Run Code Online (Sandbox Code Playgroud)
但由于缺乏文档,我无法弄清楚它在哪里如何?
目前我的STS发布了绝对到期的令牌:
protected override Lifetime GetTokenLifetime(Lifetime requestLifetime)
{
// 5 Minutes for token lifetime
var lifetime = new Lifetime(DateTime.UtcNow, DateTime.UtcNow.AddMinutes(5));
return lifetime;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都非常感谢.
从理论上讲,OwinContext环境应该可以访问请求/响应信息以及服务器变量,尽管由于某种原因,我从OwinContext无法访问Request.ServerVariables集合中可用的一些自定义服务器变量.
造成这种差异的原因是什么?我应该如何解决这个问题?
当ASP.NET MVC出现时,微软在许多地方多次宣布它不应该取代ASP.NET Web Forms.换句话说,它只是您可能觉得有用的另一种技术,或者您可能在其他场景中使用Web窗体.
然而,随着公司进入市场,他们无法拥有技术丛林,因为这太昂贵了.他们通常选择成熟的技术,坚持使用,在其基础上进行扩展,并在其中重复使用元素以降低成本.
现在我们正在尝试从Web API转移到Owin/Katana.我们只是想知道我们100%搬到Owin是否可以?
我问这个问题的原因是因为我们为Web API创建了一个非常丰富的代码库,包括流式传输,压缩,身份验证,UGC规范化,I18N和L10N支持等等.
如果我们想要迁移到Owin,我们需要再次为Owin重新创建这些工具/实用程序,因为它的体系结构与Web API不同.
我们想转移到Owin,因为它是更快,更轻,自托管的服务器,似乎是微软服务技术的未来.
我们完全转移到Owin并想象一下我们所有服务都通过Owin提供的未来,我们是否安全?我们停止使用Web API?
我正在使用 owin openid connect 身份验证,其中身份验证提供程序托管在单独的域上。身份验证过程运行良好。在身份服务器成功登录后,我能够查看受限页面。
但我希望外部身份服务器返回到“account/SignInCallback”控制器操作,以便我可以执行与成员帐户相关的几行代码。在浏览器的网络活动中,它向我显示“account/SignInCallback”的“302 Found”,但它没有命中附加的断点。它直接转到请求发起 URL,例如“帐户/仪表板”。
有没有办法可以强制系统在登录后返回特定的网址,即使请求的网址不同?
public class AccountController : BaseController
{
public AccountController() : base()
{
}
[Authorize]
public ActionResult Dashboard()
{
return View();
}
[HttpPost]
[AllowAnonymous]
public ActionResult SignInCallback()
{
if (User.Identity.IsAuthenticated)
{
// Read claims and execute member specific codes
}
return View();
}
[AllowAnonymous]
public ActionResult Unauthorized()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
启动类如下:
public sealed class Startup
{
public void Configuration(IAppBuilder app)
{
string ClientCallbackUri = @"https://client.local/account/SignInCallback";
string IdServBaseUri = @"https://idm.website.com/core";
string TokenEndpoint …Run Code Online (Sandbox Code Playgroud)