Tag: owin

Asp MVC:如何从ApplicationUser获取角色

在ASP.NET MVC 5中,在控制器中,我已经使用已发出请求的用户: ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); 使用ApplicationUser实例,我如何获得用户的所有角色?

OWIN身份validation,使当前令牌失效并删除co​​okie

我有一个OWIN中间件用于身份validation。 我们有两种类型的身份validation。 第一种类型是使用以下配置的承载令牌 var OAuthOptions = new OAuthAuthorizationServerOptions { AuthenticationType = DefaultAuthenticationTypes.ExternalBearer, TokenEndpointPath = new PathString(“/Token”), Provider = new ApplicationOAuthProvider(PublicClientId), AccessTokenExpireTimeSpan = TimeSpan.FromDays(14), AllowInsecureHttp = true, AccessTokenFormat = new SecureTokenFormatter(GetMachineKey()) }; 第二种类型使用外部登录的身份validationcookie app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ExternalCookie, AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive, CookieHttpOnly = true, CookieSecure = CookieSecureOption.SameAsRequest, CookieName = “.AspNet.” + DefaultAuthenticationTypes.ExternalCookie, ExpireTimeSpan = TimeSpan.FromMinutes(5), […]

停止自托管owin服务器时完成当前请求

我有OWIN服务器作为控制台应用程序的一部分。 你可以在这里看到主要方法: class Program { public static ManualResetEventSlim StopSwitch = new ManualResetEventSlim(); static void Main(string[] args) { Console.CancelKeyPress += (s, a) => { a.Cancel = true; StopSwitch.Set(); }; using (WebApp.Start(“http://+:8080/”)) { Console.WriteLine(“Server is running…”); Console.WriteLine(“Press CTRL+C to stop it.”); StopSwitch.Wait(); Console.WriteLine(“Server is stopping…”); } Console.ReadKey(); Console.WriteLine(“Server stopped. Press any key to close app…”); } } […]

OWin是否支持WCF?

我有一个ac #project,它通过WebApi和WCF公开服务。 它在IIS下运行。 现在我需要提供它作为自主主机解决方案。 我找不到关于Owin的文档以及如何公开WCF服务。 OWin是否支持WCF?

第一次外部登录尝试重定向回登录操作,第二次登录操作

我在我的ASP.Net MVC 5 / WebApi 2项目中使用OWIN的外部认证提供程序,我遇到了一个奇怪的问题。 登录工作流程就像在SO上一样。 用户点击登录页面,选择提供商并登录。我的问题是,首次点击提供商会重定向回相同的登录页面: http://localhost:57291/Account/Login?ReturnUrl=%2fAccount%2fExternalLogin 如果ExternalLogin操作缺少AllowAnonymous属性,这将有意义。 当用户第二次点击时一切正常。 我也尝试过使用不同的浏览器,问题在Chrome,IE11和Firefox中都是一致的。 Login.cshtml: @using (Html.BeginForm(“ExternalLogin”, “Account”, new { ReturnUrl = ViewBag.ReturnUrl })) { @Strings.ExternalAuthenticationProvidersDescription @foreach (var p in Model.ExternalAuthenticationProviders) { @p.Caption } } AccountController.cs public class AccountController : Controller { … [AllowAnonymous] [HttpPost] public ActionResult ExternalLogin(string provider, string returnUrl) { return new ChallengeResult(provider, Url.Action(“ExternalLoginCallback”, “Account”, […]

无法添加和获取自定义声明值

我正在使用带有身份2.0的mvc 5。 我想在应用程序上使用自定义声明值,但我得到null值。 我究竟做错了什么? 更新的代码 帐户控制器中的登录代码 if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password)) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var result = SignInManager.PasswordSignIn(model.UserName, model.Password, model.RememberMe, shouldLockout: false); //Generate verification token Dictionary acceccToken = null; if (SignInStatus.Success == 0) { var userDeatails = FindUser(model.UserName, model.Password).Result; if (userDeatails != null) acceccToken = GetTokenDictionary(model.UserName, model.Password, userDeatails.Id); } if (model.RememberMe) { HttpCookie userid = new HttpCookie(“rembemberTrue”, […]

在c#中手动解码OAuth承载令牌

在我的基于Web Api 2.2 OWIN的应用程序中,我有一种情况,我手动需要解码承载令牌,但我不知道如何做到这一点。 这是我的startup.cs public class Startup { public static OAuthAuthorizationServerOptions OAuthServerOptions { get; private set; } public static UnityContainer IoC; public void Configuration(IAppBuilder app) { //Set Auth configuration ConfigureOAuth(app); ….and other stuff } public void ConfigureOAuth(IAppBuilder app) { OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString(“/token”), AccessTokenExpireTimeSpan = TimeSpan.FromDays(1), […]

拒绝令牌请求时自定义OWIN / OAuth HTTP状态代码

我已经派生了OAuthAuthorizationServerProvider以validation客户端和资源所有者。 当我validation资源所有者时,我发现他们的凭据无效,我调用context.Rejected() , HTTP响应带有HTTP / 400错误请求状态代码,而我希望HTTP / 401未经授权 。 如何自定义OAuthAuthorizationServerProvider的响应HTTP状态代码?

Owin在web.config中提供启动类(没有自动启动发现)

我尝试在web.config中执行以下操作: 如果我正确理解本文档 ,则应禁用自动启动检测。 所以我不需要启动属性。 不幸的是,看起来OWIN没有启动。 (我看到这个是因为我收到错误: HTTP Error 403.14 – Forbidden 。我使用控制器来处理对索引文件的请求。) 如果我使用并添加启动属性[assembly: OwinStartup(typeof(MyStartupClass))]那么应用程序会按预期启动。 所以问题是为什么? 我该怎么做才能解决这个问题? 我正在使用OWIN 3.0.0.0 更新: 这就是我的启动类的样子(带有相关部分的缩小版): using System.Web.Http; using Microsoft.AspNet.SignalR; using Microsoft.Owin; using Owin; using MyOtherNamespace; namespace MyNamespace { public class MyOnlineStartup : MyOtherStartup { public new void Configuration(IAppBuilder app) { base.Configuration(app); //Call base method! This is important because otherwise ther […]

Owin Middleware在服务器上产生404

我有一个owin中间件,它在我的开发机器上的IIS7上工作(win7)。 但是当部署到2008服务器时,页面返回404 我像这样连接中间件 public static class AppBuilderExtensions { public static void InitTemplateStore(this IAppBuilder app, string templatePath, string fileMask) { TemplateStoreMiddleware.Init(templatePath, fileMask); app.Map(“/templates”, subApp => subApp.Use()); } } 可以在此处找到使用中间件的代码 https://github.com/AndersMalmgren/Knockout.Bootstrap.Demo 该站点作为IIS上默认网站下的虚拟应用程序托管 编辑:我是否需要添加默认角色之外的任何角色? IIS正在使用StaticFile处理程序,其中offcourse是错误的,为什么会发生这种情况? Module IIS Web Core Notification MapRequestHandler Handler StaticFile Error Code 0x80070002 Requested URL http://localhost:80/knockout.bootstrap.demo/templates?root=shared Physical Path C:\inetpub\knockout.bootstrap.demo\templates Logon Method Anonymous Logon User Anonymous