Tag: owin

为Bearer授权添加额外的逻辑

我正在尝试实施OWIN持票人令牌授权,并基于这篇文章 。 但是,在承载令牌中我需要一条额外的信息,我不知道如何实现。 在我的应用程序中,我需要从持有者令牌中推断出用户信息(比如userid)。 这很重要,因为我不希望授权用户能够充当其他用户。 这可行吗? 它甚至是正确的方法吗? 如果用户标识是guid,那么这很简单。 在这种情况下,它是一个整数。 授权用户可能只是通过猜测/暴力来冒充他人,这是不可接受的。 看看这段代码: public void ConfigureOAuth(IAppBuilder app) { OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString(“/token”), AccessTokenExpireTimeSpan = TimeSpan.FromDays(1), Provider = new SimpleAuthorizationServerProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()); } public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider { public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext […]

转换方法以使用异步

我正在转换身份validation过程以支持异步,VS 2015 IDE警告我以下消息: async方法缺少’await’运算符并将同步运行…等… 无论如何,代码连接到LDAP商店并validation用户的帐户等…我已经尝试了各种各样的东西等待,但我只是在这里遗漏了一些东西。 我把代码恢复到以前的状态..我将非常感谢能够正确支持异步的任何指导… 这是代码: public async Task GetAsyncADUser(PrincipalContextParameter param) { try { if (UseLDAPForIdentityServer3) { using (var pc = new PrincipalContext(ContextType.Domain, param.ADDomain, param.ADServerContainer, param.ADServerUser, param.ADServerUserPwd)) { UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(pc, param.UserNameToValidate); if (userPrincipal != null) { bool isvalid = pc.ValidateCredentials(userPrincipal.DistinguishedName, param.UserPasswordToValidate, ContextOptions.SimpleBind); if (isvalid) { User user = new User { ad_guid […]

configureauth这个名称不存在

我正在尝试本教程http://httpjunkie.com/2013/311/adding-mvc-5-identity-to-an-existing-project/但是显示错误错误5名称’ConfigureAuth’不存在在当前的背景下 这是我的startup.cs类 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.Owin; using Owin; [assembly: OwinStartupAttribute(typeof(TicketSystem.Startup))] namespace TicketSystem { public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); } } } 这是Startup.Auth.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Microsoft.AspNet.Identity; using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Owin; namespace TicketSystem.App_Start { […]

有没有办法让OWIN托管SOAP服务?

如何让OWIN托管SOAP端点(不管是否涉及WCF,SOAP都会提供WSDL,使得某些客户端更容易使用服务,这就是我想要SOAP和REST的原因) 我怀疑答案是:实现自己的托管SOAP端点的中间件。 如果这就是答案,那就是它,但这是很多工作,所以我可能最终会坚持使用WCF并避免OWIN,如果是这样的话。 我发现很难相信没有人实现过SOAP托管中间件…… 作为一项规则,我们喜欢在我们的服务上执行REST和SOAP端点; 目前我们使用IIS和WCF restful位来使用[ServiceContract] / [OperationContract]属性来托管SOAP,其余的是使用[WebInvoke]属性定义的,使用这些属性,服务不需要为不同的端点类型重新实现。 我们只是使用ASP.NET路由添加新的ServiceRoute ,它使用与绑定到URI / SOAP的SOAP相同的服务向URI / REST添加rest绑定。 现在我们正在寻找一些新的服务工作,我想继续使用OWIN,这样我们可以通过托管不可知论来实现我们的新服务,因为一些服务将更好地服务于Windows服务托管和一些更好的服务由IIS服务托管。 所有我都在摆弄东西,到目前为止,我无法获得由OWIN托管的SOAP端点。 通过使我的服务inheritance自ApiController ,然后在OWIN应用程序的Configuration方法中使用这一小段代码,我完成了其余的处理: public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); app.UseWebApi(config); […]

Owin舞台标记

鉴于这在我的应用程序启动… app.Use((context, next) => { return next.Invoke(); }).UseStageMarker(PipelineStage.PostAuthenticate); app.Use((context, next) => { return next.Invoke(); }).UseStageMarker(PipelineStage.Authenticate); …为什么PostAuthenticate代码在Authenticate代码之前执行? 我不是说“为什么第一个app.use在第二个app.use之前被调用”我的意思是:为什么第一个调用会在第二个调用之前调用,因为第二个应该在请求管道中更早发生? 编辑 与此问题相关: 如何在此代码中获取Windows标识?

如果你没有引用它的所有依赖项,你可以使用类库吗?

让我澄清一下: 我已经构建了一个类库,可以在几个项目中使用。 作为此DLL的一部分,我想通过扩展CookieAuthenticationProvider为Owin Cookies添加一些不同的自定义提供程序,因此我需要包含对Microsoft.Owin.Security.Cookies的引用。 这是安全的,因为将使用我的库的较新项目也使用Microsoft.Owin.Security.Cookies。 然而,有些项目比较老,不使用Owin等…如果我将库包含在其他用途​​中会不会爆炸? 或者,如果我尝试使用提供者,他们只会爆炸(因为他们不能使用它,我不会这样做)。 我想在我的库中放入一些常用的东西,而不必将每个依赖的DLL引用到每个使用它们的项目中。 我很确定我正在做的事情还可以,但我希望somone可以在我浪费很多时间之前告诉我。 如果有更好的方式,我全都耳朵。

Owin Authentication.SignIn不工作

我尝试使用owin身份validation管理器来validation用户,但User.Identity.IsAuthenticated仍然是假的。 Startup.cs public partial class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } Startup.Auth.cs public partial class Startup { public static Func<UserManager> UserManagerFactory { get; set; } public Startup() { UserManagerFactory = () => { var userManager = new UserManager(new CustomUserStore()); return userManager; }; } public void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { […]

Identity Owin是否需要LazyLoading?

tl; dr:Identity似乎要求禁用LazyLoading; 这是真的,什么是最干净的解决方法? 我使用EntityFramework 6.0.2,Identity EntityFramework 1.0.0和Identity Owin 1.0.0对一个简单的C#ASP.NET 4.5.1 MVC-5 Web应用程序进行了一些基本的AB测试,看来Owin要求延迟加载不是在ApplicationContext构造函数中禁用。 要复制该问题,只需使用Visual Studio 2013创建一个快速的MVC应用程序,使用MVC模板,将所有内容保留为默认值,但取消注释该行:’app.UseGoogleAuthentication();’ 在App_Start / Startup.Auth.cs中。 运行该应用程序并使用Google登录,完成它带您到的缩写注册页面并转到帐户/管理。 您应该会在底部看到2个Google按钮。 停止应用程序。 现在转到ApplicationContext.cs并更改构造函数,如下面的代码片段所示: public ApplicationContext() : base(“DefaultConnection”) { } //Works! public ApplicationContext() : base(“DefaultConnection”) { this.Configuration.LazyLoadingEnabled = false; } //Does not work 重试测试。 只能显示1个Google按钮。 如果LazyLoadingEnabled = false,则不会加载用户角色,登录(也可能是索赔)。 我的理论是,这是微软的监督/“未来特征”,因为Identity EntityFramework和Identity Owin都是版本1.0.0。 我的问题是,这个测试能否得到确认,最干净的工作是什么? 出于我的目的,我将使用.ToList()和其他方法在我想使用它时强制执行EagerLoading。 我并不真的需要禁用LazyLoading,如果你想总是使用预先加载,它只是一种更安全的代码编写方式。 即你错过了一个地方,它使它生产,你有一个很好的错误,在某些视图中你正在迭代模型和Model.xy y == […]

如何在我的自定义表而不是aspnet用户中使用哈希密码保存新记录?

我使用asp.net身份创建新用户但收到错误: 无法将值NULL插入列’Id’,表’Mydb.dbo.AspNetUsers’; 列不允许空值。 INSERT失败。\ r \ n语句已终止 但是在这里我没有像AspNetUsers这样的表,而是我拥有自己的用户表。 代码: Web.config:2个连接字符串 IdentityModel.cs: public class ApplicationUser : IdentityUser { public async Task GenerateUserIdentityAsync(UserManager manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType this.SecurityStamp = Guid.NewGuid().ToString(); var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return userIdentity; } public string Id […]

将.net core 2的JWT Authentication实现转移到asp.net web api 2

我在.net core 2应用程序中实现了JWT身份validation ,它工作正常。 我想在asp.net web api 2应用程序中使用此实现和结构但我收到错误 我的结构: JwtTokenBuilder类: using System; using System.Collections.Generic; using Microsoft.IdentityModel.Tokens; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Linq; namespace solution.Authentication { public sealed class JwtTokenBuilder { private SecurityKey securityKey = null; private string subject = “”; private string issuer = “”; private string audience = “”; private Dictionary claims = new […]