diff --git a/samples/OSharp.Demo.Core/Identity/UserManager.cs b/samples/OSharp.Demo.Core/Identity/UserManager.cs index d6b6aab..6015a88 100644 --- a/samples/OSharp.Demo.Core/Identity/UserManager.cs +++ b/samples/OSharp.Demo.Core/Identity/UserManager.cs @@ -47,7 +47,7 @@ public UserManager(IUserStore store, IDataProtectionProvider dataProt PasswordValidator = new PasswordValidator() { RequiredLength = 6, - RequireNonLetterOrDigit = true, + RequireNonLetterOrDigit = false, RequireDigit = true, RequireLowercase = true }; diff --git a/samples/OSharp.Demo.Web/Controllers/TestsController.cs b/samples/OSharp.Demo.Web/Controllers/TestsController.cs index 7221eb0..388d3da 100644 --- a/samples/OSharp.Demo.Web/Controllers/TestsController.cs +++ b/samples/OSharp.Demo.Web/Controllers/TestsController.cs @@ -1,19 +1,17 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; using System.Security.Claims; using System.Threading.Tasks; using System.Web.Mvc; -using OSharp.Core; +using Microsoft.AspNet.Identity; + using OSharp.Core.Caching; -using OSharp.Core.Context; using OSharp.Core.Data; using OSharp.Data.Entity; using OSharp.Core.Dependency; using OSharp.Core.Extensions; -using OSharp.Core.Logging; using OSharp.Core.Security; using OSharp.Core.Security.Models; using OSharp.Demo.Contracts; @@ -80,7 +78,9 @@ public ActionResult TestIoc() format.FormatWith("DefaultDbContext", ServiceProvider.GetService().GetHashCode()), format.FormatWith("DefaultDbContext", ServiceProvider.GetService().GetHashCode()), format.FormatWith("IRepository", ServiceProvider.GetService>().GetHashCode()), - format.FormatWith("IRepository", ServiceProvider.GetService>().GetHashCode()) + format.FormatWith("IRepository", ServiceProvider.GetService>().GetHashCode()), + format.FormatWith("UserManager", ServiceProvider.GetService>().GetHashCode()), + format.FormatWith("UserManager", ServiceProvider.GetService().GetHashCode()), }; return Content(lines.ExpandAndToString("
")); } @@ -88,23 +88,31 @@ public ActionResult TestIoc() public async Task Test1() { ClientStore clientStore = ServiceProvider.GetService(); + OperationResult result = null; //ClientInputDto clientDto = new ClientInputDto() //{ // Name = "测试客户端01", // ClientType = ClientType.Application, // Url = "http://localhost:10240", - // LogoUrl= "http://localhost:10240", + // LogoUrl = "http://localhost:10240", // RedirectUrl = "http://localhost:10240" //}; - //OperationResult result = clientStore.AddClient(clientDto).Result; + //result = await clientStore.AddClient(clientDto); ClientSecretInputDto secretDto = new ClientSecretInputDto() { Type = "Test Type", Remark = "Remark", - ClientId = 1 + ClientId = 2 }; - OperationResult result = await clientStore.AddClientSecret(secretDto); + result = await clientStore.AddClientSecret(secretDto); return Content(result.Message); } + + public async Task Test2() + { + UserManager manager = ServiceProvider.GetService(); + IdentityResult result = await manager.AddPasswordAsync(1, "gmf31529019"); + return Content(result.ToJsonString()); + } } } \ No newline at end of file diff --git a/samples/OSharp.Demo.Web/Startup.cs b/samples/OSharp.Demo.Web/Startup.cs index acd437e..8ff599a 100644 --- a/samples/OSharp.Demo.Web/Startup.cs +++ b/samples/OSharp.Demo.Web/Startup.cs @@ -51,12 +51,13 @@ public void Configuration(IAppBuilder app) services.AddOAuthServices(); services.AddDemoServices(app); - app.UseOsharpMvc(new MvcAutofacIocBuilder(services)); - IIocBuilder apiAutofacIocBuilder = new WebApiAutofacIocBuilder(services); - app.UseOsharpWebApi(apiAutofacIocBuilder); + IIocBuilder mvcIocBuilder = new MvcAutofacIocBuilder(services); + app.UseOsharpMvc(mvcIocBuilder); + IIocBuilder apiIocBuilder = new WebApiAutofacIocBuilder(services); + app.UseOsharpWebApi(apiIocBuilder); //app.UseOsharpSignalR(new SignalRAutofacIocBuilder(services)); - app.ConfigureOAuth(apiAutofacIocBuilder.ServiceProvider); + app.ConfigureOAuth(apiIocBuilder.ServiceProvider); app.ConfigureWebApi(); //app.ConfigureSignalR(); } diff --git a/samples/OSharp.Demo.Web/osharp.config b/samples/OSharp.Demo.Web/osharp.config index f5dadb2..517c73a 100644 --- a/samples/OSharp.Demo.Web/osharp.config +++ b/samples/OSharp.Demo.Web/osharp.config @@ -2,7 +2,7 @@ - + diff --git a/src/OSharp.App.Local/Initialize/AutofacRegistration.cs b/src/OSharp.App.Local/Initialize/AutofacRegistration.cs index 94ac466..af36d9f 100644 --- a/src/OSharp.App.Local/Initialize/AutofacRegistration.cs +++ b/src/OSharp.App.Local/Initialize/AutofacRegistration.cs @@ -54,6 +54,7 @@ private static void RegisterInternal(ContainerBuilder builder, IEnumerable - diff --git a/src/OSharp.Autofac.Mvc/app.config b/src/OSharp.Autofac.Mvc/app.config deleted file mode 100644 index 6d58373..0000000 --- a/src/OSharp.Autofac.Mvc/app.config +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/OSharp.Autofac.SignalR/AutofacRegistration.cs b/src/OSharp.Autofac.SignalR/AutofacRegistration.cs index 94ac466..af36d9f 100644 --- a/src/OSharp.Autofac.SignalR/AutofacRegistration.cs +++ b/src/OSharp.Autofac.SignalR/AutofacRegistration.cs @@ -54,6 +54,7 @@ private static void RegisterInternal(ContainerBuilder builder, IEnumerable - diff --git a/src/OSharp.Autofac.SignalR/app.config b/src/OSharp.Autofac.SignalR/app.config deleted file mode 100644 index c270a72..0000000 --- a/src/OSharp.Autofac.SignalR/app.config +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/OSharp.Autofac.WebApi/AutofacRegistration.cs b/src/OSharp.Autofac.WebApi/AutofacRegistration.cs index 94ac466..af36d9f 100644 --- a/src/OSharp.Autofac.WebApi/AutofacRegistration.cs +++ b/src/OSharp.Autofac.WebApi/AutofacRegistration.cs @@ -54,6 +54,7 @@ private static void RegisterInternal(ContainerBuilder builder, IEnumerable - diff --git a/src/OSharp.Autofac.WebApi/app.config b/src/OSharp.Autofac.WebApi/app.config deleted file mode 100644 index 0a5769a..0000000 --- a/src/OSharp.Autofac.WebApi/app.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/OSharp.Core/Dependency/IocBuilderBase.cs b/src/OSharp.Core/Dependency/IocBuilderBase.cs index c0cee47..47a9143 100644 --- a/src/OSharp.Core/Dependency/IocBuilderBase.cs +++ b/src/OSharp.Core/Dependency/IocBuilderBase.cs @@ -4,7 +4,7 @@ // // http://www.osharp.org // 郭明锋 -// 2015-10-12 15:33 +// 2015-11-09 3:05 // ----------------------------------------------------------------------- using System; @@ -22,8 +22,7 @@ public abstract class IocBuilderBase : IIocBuilder { private readonly IServiceCollection _services; private bool _isBuilded; - private IServiceProvider _provider; - + /// /// 初始化一个类型的新实例 /// @@ -32,6 +31,7 @@ protected IocBuilderBase(IServiceCollection services) { AssemblyFinder = new DirectoryAssemblyFinder(); _services = services.Clone(); + _isBuilded = false; } /// @@ -42,19 +42,7 @@ protected IocBuilderBase(IServiceCollection services) /// /// 获取 服务提供者 /// - public IServiceProvider ServiceProvider - { - get - { - if (_isBuilded) - { - return _provider; - } - _provider = Build(); - _isBuilded = true; - return _provider; - } - } + public IServiceProvider ServiceProvider { get; private set; } /// /// 开始构建依赖注入映射 @@ -64,7 +52,7 @@ public IServiceProvider Build() { if (_isBuilded) { - return _provider; + return ServiceProvider; } //设置各个框架的DependencyResolver @@ -72,9 +60,9 @@ public IServiceProvider Build() AddCustomTypes(_services); - _provider = BuildAndSetResolver(_services, assemblies); + ServiceProvider = BuildAndSetResolver(_services, assemblies); _isBuilded = true; - return _provider; + return ServiceProvider; } /// diff --git a/src/OSharp.Permissions.OAuth/OsharpAuthorizationServerProvider.cs b/src/OSharp.Permissions.OAuth/OsharpAuthorizationServerProvider.cs index 04894c1..09c160c 100644 --- a/src/OSharp.Permissions.OAuth/OsharpAuthorizationServerProvider.cs +++ b/src/OSharp.Permissions.OAuth/OsharpAuthorizationServerProvider.cs @@ -14,6 +14,7 @@ using OSharp.Core.Identity; using OSharp.Core.Security.Properties; using OSharp.Utility; +using OSharp.Utility.Extensions; namespace OSharp.Core.Security @@ -73,7 +74,11 @@ public override Task GrantClientCredentials(OAuthGrantClientCredentialsContext c { ClaimsIdentity identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, context.ClientId)); - identity.AddClaims(context.Scope.Select(m => new Claim("urn:oauth:scope", m))); + List scopes = context.Scope.Where(m => !m.IsMissing()).ToList(); + if (scopes.Any()) + { + identity.AddClaims(scopes.Select(m => new Claim("urn:oauth:scope", m))); + } AuthenticationProperties properties = new AuthenticationProperties( new Dictionary() { { "as:client_id", context.ClientId } }); @@ -99,10 +104,14 @@ public async override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwner //生成令牌 ClaimsIdentity identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); - identity.AddClaims(context.Scope.Select(m => new Claim("urn:oauth:scope", m))); + List scopes = context.Scope.Where(m => !m.IsMissing()).ToList(); + if (scopes.Any()) + { + identity.AddClaims(scopes.Select(m => new Claim("urn:oauth:scope", m))); + } AuthenticationProperties properties = new AuthenticationProperties( - new Dictionary() { {"as:client_id", context.ClientId} }); + new Dictionary() { { "as:client_id", context.ClientId } }); AuthenticationTicket ticket = new AuthenticationTicket(identity, properties); context.Validated(ticket); } @@ -114,11 +123,6 @@ public async override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwner /// public override Task GrantRefreshToken(OAuthGrantRefreshTokenContext context) { - //if (context.Ticket == null || context.Ticket.Identity == null || !context.Ticket.Identity.IsAuthenticated) - //{ - // context.SetError("invalid_grant", "Refresh token is not valid"); - //} - //return base.GrantRefreshToken(context); string originalClient = context.Ticket.Properties.Dictionary["as:client_id"]; string currentClient = context.ClientId; if (originalClient != currentClient)