public async Task <IdentityPrincipal> RemoveAsync(IWorkContext context, PrincipalId principalId) { Verify.IsNotNull(nameof(context), context); Verify.IsNotEmpty(nameof(principalId), principalId); IIdentityActor actor = await _actorManger.CreateProxyAsync <IIdentityActor>(context, new ActorKey(principalId)); return(await actor.Remove(context)); }
public async Task SetAsync(IWorkContext context, IdentityPrincipal identityPrincipal) { Verify.IsNotNull(nameof(context), context); Verify.IsNotNull(nameof(identityPrincipal), identityPrincipal); IIdentityActor actor = await _actorManger.CreateProxyAsync <IIdentityActor>(context, new ActorKey(identityPrincipal.PrincipalId)); await actor.Set(context, identityPrincipal); }
public async Task CertificateSetGetTest() { IWorkContext context = _workContext.WithMethodName(); var identityRepository = new IdentityInMemoryStore() .Set(_workContext, new IdentityPrincipal(new PrincipalId("*****@*****.**"), IdentityPrincipalType.User).With(new ApiKey("API Key1", DateTime.UtcNow.AddYears(1)))) .Set(_workContext, new IdentityPrincipal(new PrincipalId("*****@*****.**"), IdentityPrincipalType.User).With(new ApiKey("API Key2", DateTime.UtcNow.AddYears(1)))); var builder = new ContainerBuilder(); builder.RegisterModule(new IdentityActorAutoFacModule()); builder.RegisterInstance(identityRepository).As <IIdentityStore>(); ILifetimeScope container = builder.Build(); IActorManager manager = new ActorConfigurationBuilder() .AddIdentityModule(container) .Build() .ToActorManager(); using (ILifetimeScope scopeContainer = container.BeginLifetimeScope()) using (manager) { IIdentityActor clientActor1 = await manager.CreateProxyAsync <IIdentityActor>(context, new ActorKey("*****@*****.**")); IdentityPrincipal client1 = await clientActor1.Get(context); client1.Should().NotBeNull(); client1.PrincipalId.Value.Should().Be("*****@*****.**"); client1.ApiKey.Value.Should().Be("API Key1"); IIdentityActor clientActor2 = await manager.CreateProxyAsync <IIdentityActor>(context, new ActorKey("*****@*****.**")); IdentityPrincipal client2 = await clientActor2.Get(context); client2.Should().NotBeNull(); client2.PrincipalId.Value.Should().Be("*****@*****.**"); client2.ApiKey.Value.Should().Be("API Key2"); await clientActor2.Remove(context); (await clientActor2.Get(context)).Should().BeNull(); identityRepository.Get(context, new PrincipalId("*****@*****.**")).Should().BeNull(); await clientActor2.Set(context, new IdentityPrincipal(new PrincipalId("*****@*****.**"), IdentityPrincipalType.User)); (await clientActor2.Get(context)).Should().NotBeNull(); identityRepository.Get(context, new PrincipalId("*****@*****.**")).Should().NotBeNull(); } await Verify.AssertExceptionAsync <ArgumentException>(async() => await manager.DeactivateAllAsync(_workContext)); }