Esempio n. 1
0
 public async Task <int> DeleteClientClaimAsync(ClientClaim clientClaim)
 {
     using (var dbContext = ConnectionDatabase.Get(_configuration))
     {
         return(await dbContext.ExecuteAsync("delete from ClientClaims where id=@Id", new { clientClaim.Id }));
     }
 }
        public async Task <ClientClaim> AddClientClaim(ClientClaim clientClaim)
        {
            _context.ClientClaims.Add(clientClaim);
            await _context.SaveChangesAsync();

            return(clientClaim);
        }
        public TokenExchangeGrantResult Build()
        {
            if (!this.isError)
            {
                this.logger.LogInformation(this.successMessage);

                var act = this.BuildActClaim(this.options.ActorClaimsToInclude);

                if (this.IsClientToClientDelegation)
                {
                    var actClientClaim = new ClientClaim(act.Type, act.Value, act.ValueType);
                    this.subjectClient.Claims.Add(actClientClaim);
                    return(new TokenExchangeGrantResult(this.subjectClient));
                }

                this.subjectUserClaims.Add(act);
                var filteredSubjectClaims = this.subjectUserClaims.Where(c => !this.options.SubjectClaimsToExclude.Any(t => t.Contains(c.Type))).ToList();

                return(new TokenExchangeGrantResult(
                           this.subject,
                           filteredSubjectClaims,
                           this.subjectClient,
                           this.subjectUserClaims.Idp() ?? IdentityServerConstants.LocalIdentityProvider));
            }

            this.logger.LogError(this.logMessage ?? this.errorDescription);

            return(new TokenExchangeGrantResult(this.error, this.errorDescription));
        }
Esempio n. 4
0
        public async Task <bool> Handle(SaveClientClaimCommand request, CancellationToken cancellationToken)
        {
            if (request.IsValid() == false)
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var client = await _clientRepository.FindByClientIdAsync(request.ClientId);

            if (client == null)
            {
                await _bus.RaiseEvent(new DomainNotification("key_not_found", $"Client named {request.ClientId} not found"));

                return(false);
            }

            var claim = new ClientClaim
            {
                Client = client,
                Type   = request.Type,
                Value  = request.Value
            };

            await _clientClaimRepository.AddAsync(claim);

            if (Commit())
            {
                await _bus.RaiseEvent(new ClientClaimAddedEvent(request.ClientId, claim.Id, claim.Type, claim.Value));

                return(true);
            }

            return(false);
        }
        public async Task <bool> Handle(SaveClientClaimCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var savedClient = await _clientRepository.GetByClientId(request.ClientId);

            if (savedClient == null)
            {
                await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));

                return(false);
            }

            var property = new ClientClaim()
            {
                Client = savedClient,
                Value  = request.Value,
                Type   = request.Type
            };

            _clientClaimRepository.Add(property);

            if (Commit())
            {
                await Bus.RaiseEvent(new NewClientClaimEvent(request.Id, request.ClientId, property.Type, property.Value));

                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        public async Task <int> DeleteClientClaimAsync(ClientClaim clientClaim)
        {
            var claimToDelete = await _dbContext.ClientClaims.Where(x => x.Id == clientClaim.Id).SingleOrDefaultAsync();

            _dbContext.ClientClaims.Remove(claimToDelete);
            return(await AutoSaveChangesAsync());
        }
Esempio n. 7
0
        public async Task <int> AddClientClaimAsync(int clientId, ClientClaim clientClaim)
        {
            var client = await _dbContext.Clients.Where(x => x.Id == clientId).SingleOrDefaultAsync();

            clientClaim.Client = client;
            await _dbContext.ClientClaims.AddAsync(clientClaim);

            return(await AutoSaveChangesAsync());
        }
Esempio n. 8
0
 public static ClaimModel FromEntity(ClientClaim claim)
 {
     return(new ClaimModel
     {
         Id = claim.Id,
         Type = claim.Type,
         Value = claim.Value,
         Client = ClientModel.FromEntity(claim.Client),
     });
 }
        public async Task <int> Insert(ClientClaim clientClaim)
        {
            var isExists = await CheckExists(clientClaim.Id, clientClaim.ClientId, clientClaim.ClaimType);

            if (isExists)
            {
                return(-1);
            }

            _clientClaimRepository.Create(clientClaim);
            return(await Context.SaveChangesAsync());
        }
Esempio n. 10
0
 public async Task <int> AddClientClaimAsync(int clientId, ClientClaim clientClaim)
 {
     using (var dbContext = ConnectionDatabase.Get(_configuration))
     {
         return(await dbContext.QueryFirstAsync <int>("insert into ClientClaims values(@Type, @Value, @clientId); select SCOPE_IDENTITY();", new
         {
             clientClaim.Type,
             clientClaim.Value,
             clientId
         }));
     }
 }
Esempio n. 11
0
        private async Task SaveClientClaims(string siteId, Client client, CancellationToken cancellationToken = default(CancellationToken))
        {
            foreach (var c in client.Claims)
            {
                var cc = new ClientClaim
                {
                    Id       = Guid.NewGuid().ToString(),
                    ClientId = client.ClientId,
                    Type     = c.Type,
                    Value    = c.Value
                };

                await _claimCommands.CreateAsync(siteId, cc.Id, cc, cancellationToken).ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Add new Client Claim
        /// </summary>
        /// <param name="claim"></param>
        /// <returns></returns>
        public async Task <string> AddClaim(ClientClaim claim)
        {
            string result = "";
            await Task.Run(() => {
                try {
                    using (/*var*/ ctx /*= new ResourceConfigDbContext()*/) {
                        ctx.ClientClaims.Add(claim);
                        ctx.SaveChanges();
                        result = "ClaimId " + claim.Id.ToString();
                    }
                }
                catch (Exception ex) {
                    result = ex.Message;
                }
            });

            return(result);
        }
        public async Task <int> Update(ClientClaim clientClaim)
        {
            var isExists = await CheckExists(clientClaim.Id, clientClaim.ClientId, clientClaim.ClaimType);

            if (isExists)
            {
                return(-1);
            }

            var info = await GetInfo(clientClaim.Id);

            if (info == null)
            {
                return(-2);
            }

            info.ClaimType  = clientClaim.ClaimType;
            info.ClaimValue = clientClaim.ClaimValue;
            return(await Context.SaveChangesAsync());
        }
Esempio n. 14
0
 public async Task<IActionResult> AddClientClaim([FromRoute]string clientId, [FromBody]CreateClaimRequest request) {
     var client = await _configurationDbContext.Clients.SingleOrDefaultAsync(x => x.ClientId == clientId);
     if (client == null) {
         return NotFound();
     }
     var claimToAdd = new ClientClaim {
         Client = client,
         ClientId = client.Id,
         Type = request.Type,
         Value = request.Value
     };
     client.Claims = new List<ClientClaim> {
         claimToAdd
     };
     await _configurationDbContext.SaveChangesAsync();
     return Created(string.Empty, new ClaimInfo {
         Id = claimToAdd.Id,
         Type = claimToAdd.Type,
         Value = claimToAdd.Value
     });
 }
Esempio n. 15
0
        /// <summary>
        /// Gets the value of the first claim that matches the given claim type
        /// or null if not found.
        /// </summary>
        /// <param name="claimType">Type of the claim.</param>
        /// <returns>The value of the matched claim.</returns>
        public static string GetSpecificClaimValue(string claimType)
        {
            ClientClaim specificClaim = null;

            foreach (ClientClaim claim in ClientClaims)
            {
                if (claim.ClaimType == claimType)
                {
                    specificClaim = claim;
                    break;
                }
            }

            if (specificClaim == null)
            {
                return(null);
            }
            else
            {
                return(specificClaim.Value);
            }
        }
 public Task <string> UpdateClaim(ClientClaim claim)
 {
     throw new NotImplementedException();
 }
        private void AddClients(Client ct)
        {
            var client = new Client <Guid>()
            {
                AbsoluteRefreshTokenLifetime = ct.AbsoluteRefreshTokenLifetime,
                AccessTokenLifetime          = ct.AccessTokenLifetime,
                AccessTokenType            = ct.AccessTokenType,
                AllowAccessToAllGrantTypes = ct.AllowAccessToAllCustomGrantTypes,
                AllowAccessToAllScopes     = ct.AllowAccessToAllScopes,
                AllowClientCredentialsOnly = ct.AllowClientCredentialsOnly,
                AllowPromptNone            = ct.AllowPromptNone,
                AllowRememberConsent       = ct.AllowRememberConsent,
                AlwaysSendClientClaims     = ct.AlwaysSendClientClaims,
                AuthorizationCodeLifetime  = ct.AuthorizationCodeLifetime,
                ClientId                    = ct.ClientId,
                ClientName                  = ct.ClientName,
                ClientUri                   = ct.ClientUri,
                EnableLocalLogin            = ct.EnableLocalLogin,
                Enabled                     = ct.Enabled,
                Flow                        = ct.Flow,
                IdentityTokenLifetime       = ct.IdentityTokenLifetime,
                IncludeJwtId                = ct.IncludeJwtId,
                LogoUri                     = ct.LogoUri,
                LogoutSessionRequired       = ct.LogoutSessionRequired,
                LogoutUri                   = ct.LogoutUri,
                PrefixClientClaims          = ct.PrefixClientClaims,
                RefreshTokenExpiration      = ct.RefreshTokenExpiration,
                RefreshTokenUsage           = ct.RefreshTokenUsage,
                RequireConsent              = ct.RequireConsent, //设置为true会有问题?
                SlidingRefreshTokenLifetime = ct.SlidingRefreshTokenLifetime,
                UpdateAccessTokenOnRefresh  = ct.UpdateAccessTokenClaimsOnRefresh
            };

            client.ClientSecrets = new List <ClientSecret <Guid> >();
            client.AllowedScopes = new List <ClientScope <Guid> >();
            client.RedirectUris  = new List <ClientRedirectUri <Guid> >();
            client.IdentityProviderRestrictions = new List <ClientProviderRestriction <Guid> >();
            client.PostLogoutRedirectUris       = new List <ClientPostLogoutRedirectUri <Guid> >();
            client.AllowedCustomGrantTypes      = new List <ClientCustomGrantType <Guid> >();
            client.Claims             = new List <ClientClaim <Guid> >();
            client.AllowedCorsOrigins = new List <ClientCorsOrigin <Guid> >();

            //Add Secrets
            foreach (var secret in ct.ClientSecrets)
            {
                var clientSecret = new ClientSecret <Guid>()
                {
                    Description = secret.Description,
                    Expiration  = secret.Expiration.HasValue ? (DateTime?)secret.Expiration.Value.DateTime : null,
                    Type        = secret.Type,
                    Value       = secret.Value
                };
                client.ClientSecrets.Add(clientSecret);
            }
            //Add Scopes
            foreach (var scope in ct.AllowedScopes)
            {
                var allowedScope = new ClientScope <Guid>()
                {
                    Scope = scope
                };
                client.AllowedScopes.Add(allowedScope);
            }

            //Add RedirectUris
            foreach (var redirectUri in ct.RedirectUris)
            {
                var clientRedirectUri = new ClientRedirectUri <Guid>()
                {
                    Uri = redirectUri
                };
                client.RedirectUris.Add(clientRedirectUri);
            }
            //Add ProviderRestrictions
            foreach (var provider in ct.IdentityProviderRestrictions)
            {
                var clientProviderRestriction = new ClientProviderRestriction <Guid>()
                {
                    Provider = provider
                };
                client.IdentityProviderRestrictions.Add(clientProviderRestriction);
            }
            //Add ClientPostLogoutRedirectUri
            foreach (var postLogoutRedirectUri in ct.PostLogoutRedirectUris)
            {
                var clientPostLogoutRedirectUri = new ClientPostLogoutRedirectUri <Guid>()
                {
                    Uri = postLogoutRedirectUri
                };
                client.PostLogoutRedirectUris.Add(clientPostLogoutRedirectUri);
            }
            //Add ClientCustomGrantTypes
            foreach (var customGrantType in ct.AllowedCustomGrantTypes)
            {
                var clientCustomerGrantType = new ClientCustomGrantType <Guid>()
                {
                    GrantType = customGrantType
                };
                client.AllowedCustomGrantTypes.Add(clientCustomerGrantType);
            }
            //Add ClientClaims
            foreach (var claim in ct.Claims)
            {
                var clientClaim = new ClientClaim <Guid>()
                {
                    Type  = claim.Type,
                    Value = claim.Value
                };
                client.Claims.Add(clientClaim);
            }
            //Add ClientCorsOrigins
            foreach (var corsOrigin in ct.AllowedCorsOrigins)
            {
                var clientCorsOrigin = new ClientCorsOrigin <Guid>()
                {
                    Origin = corsOrigin
                };
                client.AllowedCorsOrigins.Add(clientCorsOrigin);
            }
            _clientContext.Clients.Add(client);
            _clientContext.SaveChanges();
        }
Esempio n. 18
0
 public async Task <bool> DeleteClientClaim(ClientClaim clientClaim)
 {
     return(await _repository.DeleteAsync(clientClaim));
 }
Esempio n. 19
0
 public static ClientClaimModel ToModel(this ClientClaim clientClaim)
 {
     return(Mapper.Map <ClientClaimModel>(clientClaim));
 }
Esempio n. 20
0
 public static ClientClaimsDto ToModel(this ClientClaim clientClaim, IMapper mapper)
 {
     return(mapper.Map <ClientClaimsDto>(clientClaim));
 }
Esempio n. 21
0
        public async Task OnPostAsync()
        {
            // Arrange
            const string claim1OriginalValue = "Original Value";
            const string claim1EditedValue   = "Edited Value";
            const string newClaimValue       = "New Value";
            var          databaseName        = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}";
            var          options             = new DbContextOptionsBuilder <OidcDbContext>()
                                               .UseInMemoryDatabase(databaseName)
                                               .Options;
            ClaimsModel   claims;
            IActionResult post;
            var           claim1 = new ClientClaim
            {
                Id    = Random.Next(),
                Value = claim1OriginalValue
            };
            var claim2 = new ClientClaim {
                Id = Random.Next()
            };
            var client = new Client
            {
                Id     = Random.Next(),
                Claims = new List <ClientClaim>
                {
                    claim1,
                    claim2
                }
            };

            using (var context = new OidcDbContext(options))
            {
                context.Add(client);
                await context.SaveChangesAsync().ConfigureAwait(false);
            }

            // Act
            using (var context = new OidcDbContext(options))
            {
                claims = new ClaimsModel(context)
                {
                    Client = new Client
                    {
                        Id     = client.Id,
                        Claims = new List <ClientClaim>
                        {
                            new ClientClaim
                            {
                                Id    = claim1.Id,
                                Value = claim1EditedValue
                            },
                            new ClientClaim {
                                Value = newClaimValue
                            }
                        }
                    }
                };
                post = await claims.OnPostAsync().ConfigureAwait(false);
            }

            // Assert
            using (var context = new OidcDbContext(options))
            {
                client = await context.Clients
                         .Include(x => x.Claims)
                         .SingleOrDefaultAsync(x => x.Id.Equals(client.Id))
                         .ConfigureAwait(false);

                claim1 = client.Claims.SingleOrDefault(x => x.Id.Equals(claim1.Id));
                claim2 = client.Claims.SingleOrDefault(x => x.Id.Equals(claim2.Id));
                var newClaim = client.Claims.SingleOrDefault(x => x.Value.Equals(newClaimValue));

                Assert.NotNull(claim1);
                Assert.Equal(claim1EditedValue, claim1.Value);
                Assert.Null(claim2);
                Assert.NotNull(newClaim);
            }

            var result = Assert.IsType <RedirectToPageResult>(post);

            Assert.Equal("../Details/Claims", result.PageName);
            Assert.Collection(result.RouteValues, routeValue =>
            {
                var(key, value) = routeValue;
                Assert.Equal(nameof(Client.Id), key);
                Assert.Equal(claims.Client.Id, value);
            });
        }
Esempio n. 22
0
        public Result <int> Update(ClientModel model, int id)
        {
            try
            {
                var result         = new Result <int>();
                var existingClient = clientContext.Clients
                                     .Where(x => x.Id == id)
                                     .Include(x => x.AllowedScopes)
                                     .Include(x => x.ClientSecrets)
                                     .Include(x => x.RedirectUris)
                                     .Include(x => x.PostLogoutRedirectUris)
                                     .Include(x => x.AllowedCorsOrigins)
                                     .Include(x => x.IdentityProviderRestrictions)
                                     .Include(x => x.Claims)
                                     .Include(x => x.AllowedCustomGrantTypes)
                                     .SingleOrDefault();


                if (existingClient == null)
                {
                    result.Exists = false;
                    return(result);
                }

                var duplicateClientId = clientContext.Clients
                                        .Where(x => x.ClientId == model.ClientId)
                                        .FirstOrDefault();

                if (duplicateClientId != null && duplicateClientId.Id != id)
                {
                    throw new Exception("pre-existing clientid");
                }

                clientContext.Entry(existingClient).CurrentValues.SetValues(model); // copy all values from object

                #region Update related properties


                var exRedirectUris = existingClient.RedirectUris.ToList();
                //delete redirect uri's that have been removed
                foreach (var item in exRedirectUris)
                {
                    if (!model.RedirectUris.Any(x => x.Id == item.Id))
                    {
                        existingClient.RedirectUris.Remove(item);
                    }
                }
                if (model.RedirectUris != null && model.RedirectUris.Any())
                {
                    //update and add new uris
                    foreach (var item in model.RedirectUris)
                    {
                        var exRedirectUri = existingClient.RedirectUris.FirstOrDefault(x => x.Id == item.Id);
                        if (exRedirectUri != null)
                        {
                            clientContext.Entry(exRedirectUri).CurrentValues.SetValues(item);
                        }
                        else
                        {
                            var redirectUri = new ClientRedirectUri
                            {
                                Uri = item.Uri,
                            };
                            existingClient.RedirectUris.Add(redirectUri);
                        }
                    }
                }


                //delete post redirect uri's that have been removed

                var exPostRedirectUris = existingClient.PostLogoutRedirectUris.ToList();
                foreach (var item in exPostRedirectUris)
                {
                    if (!model.PostLogoutRedirectUris.Any(x => x.Id == item.Id))
                    {
                        existingClient.PostLogoutRedirectUris.Remove(item);
                    }
                }

                if (model.PostLogoutRedirectUris != null && model.PostLogoutRedirectUris.Any())
                {
                    foreach (var item in model.PostLogoutRedirectUris)
                    {
                        var exPostRedirectUri = existingClient.PostLogoutRedirectUris.FirstOrDefault(x => x.Id == item.Id);
                        if (exPostRedirectUri != null)
                        {
                            clientContext.Entry(exPostRedirectUri).CurrentValues.SetValues(item);
                        }
                        else
                        {
                            var postRedirectUri = new ClientPostLogoutRedirectUri
                            {
                                Uri = item.Uri,
                            };
                            existingClient.PostLogoutRedirectUris.Add(postRedirectUri);
                        }
                    }
                }
                //update and add new post redirect uris



                var exIdProvRestrictions = existingClient.IdentityProviderRestrictions.ToList();
                foreach (var item in exIdProvRestrictions)
                {
                    if (!model.IdentityProviderRestrictions.Any(x => x.Id == item.Id))
                    {
                        existingClient.IdentityProviderRestrictions.Remove(item);
                    }
                }

                if (model.IdentityProviderRestrictions != null && model.IdentityProviderRestrictions.Any())
                {
                    foreach (var item in model.IdentityProviderRestrictions)
                    {
                        var exIdProvRestriction = existingClient.IdentityProviderRestrictions.FirstOrDefault(x => x.Id == item.Id);
                        if (exIdProvRestriction != null)
                        {
                            clientContext.Entry(exIdProvRestriction).CurrentValues.SetValues(item);
                        }
                        else
                        {
                            var IdentityProvRestriction = new ClientIdPRestriction
                            {
                                Provider = item.Provider,
                            };
                            existingClient.IdentityProviderRestrictions.Add(exIdProvRestriction);
                        }
                    }
                }
                //update and add new post redirect uris



                //delete post redirect uri's that have been removed


                //delete allowed scopes that have been removed

                var exScopes = existingClient.AllowedScopes.ToList();
                foreach (var item in exScopes)
                {
                    if (!model.AllowedScopes.Any(x => x.Id == item.Id))
                    {
                        existingClient.AllowedScopes.Remove(item);
                    }
                }

                if (model.AllowedScopes != null && model.AllowedScopes.Any())
                {
                    foreach (var item in model.AllowedScopes)
                    {
                        var exScope = existingClient.AllowedScopes.FirstOrDefault(x => x.Id == item.Id);
                        if (exScope != null)
                        {
                            clientContext.Entry(exScope).CurrentValues.SetValues(item);
                        }
                        else
                        {
                            var newScope = new ClientScope
                            {
                                Scope = item.Scope,
                            };
                            existingClient.AllowedScopes.Add(newScope);
                        }
                    }
                }



                //delete client claims that have been removed
                var exClaims = existingClient.Claims.ToList();
                foreach (var item in exClaims)
                {
                    if (!model.Claims.Any(x => x.Id == item.Id))
                    {
                        existingClient.Claims.Remove(item);
                    }
                }

                if (model.Claims != null && model.Claims.Any())
                {
                    //update and add new post redirect uris
                    foreach (var item in model.Claims)
                    {
                        var exClaim = existingClient.Claims.FirstOrDefault(x => x.Id == item.Id);
                        if (exClaim != null)
                        {
                            clientContext.Entry(exClaim).CurrentValues.SetValues(item);
                        }
                        else
                        {
                            var newClaim = new ClientClaim
                            {
                                Type  = item.Type,
                                Value = item.Value
                            };
                            existingClient.Claims.Add(newClaim);
                        }
                    }
                }

                //delete client claims that have been removed

                var exAllowedCors = existingClient.AllowedCorsOrigins.ToList();
                foreach (var item in exAllowedCors)
                {
                    if (!model.AllowedCorsOrigins.Any(x => x.Id == item.Id))
                    {
                        existingClient.AllowedCorsOrigins.Remove(item);
                    }
                }

                if (model.AllowedCorsOrigins != null && model.AllowedCorsOrigins.Any())
                {
                    //update and add new post redirect uris
                    foreach (var item in model.AllowedCorsOrigins)
                    {
                        var exAllowedCor = existingClient.AllowedCorsOrigins.FirstOrDefault(x => x.Id == item.Id);
                        if (exAllowedCor != null)
                        {
                            clientContext.Entry(exAllowedCor).CurrentValues.SetValues(item);
                        }
                        else
                        {
                            var newClientCor = new ClientCorsOrigin
                            {
                                Origin = item.Origin
                            };
                            existingClient.AllowedCorsOrigins.Add(newClientCor);
                        }
                    }
                }



                //delete custom grant types that have been removed

                var exCustomGrants = existingClient.AllowedCustomGrantTypes.ToList();
                foreach (var item in exCustomGrants)
                {
                    if (!model.AllowedCustomGrantTypes.Any(x => x.Id == item.Id))
                    {
                        existingClient.AllowedCustomGrantTypes.Remove(item);
                    }
                }

                if (model.AllowedCustomGrantTypes != null && model.AllowedCustomGrantTypes.Any())
                {
                    //update and add new post redirect uris
                    foreach (var item in model.AllowedCustomGrantTypes)
                    {
                        var exCustomGrant = existingClient.AllowedCustomGrantTypes.FirstOrDefault(x => x.Id == item.Id);
                        if (exCustomGrant != null)
                        {
                            clientContext.Entry(exCustomGrant).CurrentValues.SetValues(item);
                        }
                        else
                        {
                            var newCustomGrant = new ClientCustomGrantType
                            {
                                GrantType = item.GrantType
                            };
                            existingClient.AllowedCustomGrantTypes.Add(newCustomGrant);
                        }
                    }
                }



                //delete custom grant types that have been removed

                var exSecrets = existingClient.ClientSecrets.ToList();
                foreach (var item in exSecrets)
                {
                    if (!model.ClientSecrets.Any(x => x.Id == item.Id))
                    {
                        existingClient.ClientSecrets.Remove(item);
                    }
                }

                if (model.ClientSecrets != null && model.ClientSecrets.Any())
                {
                    //update and add new post redirect uris
                    foreach (var item in model.ClientSecrets)
                    {
                        var exSecret = existingClient.ClientSecrets.FirstOrDefault(x => x.Id == item.Id);
                        if (exSecret != null)
                        {
                            exSecret.Value = exSecret.Value;
                            clientContext.Entry(exSecret).CurrentValues.SetValues(item);
                        }
                        else
                        {
                            var newSecret = new ClientSecret
                            {
                                Type        = item.Type,
                                Value       = item.Value.Sha256(),
                                Expiration  = item.Expiration,
                                Description = item.Description,
                            };
                            existingClient.ClientSecrets.Add(newSecret);
                        }
                    }
                }


                #endregion


                clientContext.SaveChanges();
                result.Exists      = true;
                result.Response    = existingClient.Id;
                result.CustomValue = existingClient.ClientName;
                return(result);
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                throw;
            }
        }
Esempio n. 23
0
 public async Task <int> InsertClientClaim(ClientClaim clientClaim)
 {
     return(await _repository.InsertAsync(clientClaim));
 }
Esempio n. 24
0
 public static ClaimDTO ToDTO(this ClientClaim entity)
 {
     return(entity == null ? null : Mapper.Map <ClaimDTO>(entity));
 }
Esempio n. 25
0
        public void UpdateClientToken(int id, ClientDto clientDto)
        {
            Client client = this.Session.Get <Client>(id);

            if (client == null)
            {
                throw new FluentValidationException($"客户端{id}不存在。");
            }
            client.IdentityTokenLifetime            = clientDto.IdentityTokenLifetime;
            client.AccessTokenLifetime              = clientDto.AccessTokenLifetime;
            client.AccessTokenType                  = clientDto.AccessTokenType;
            client.AuthorizationCodeLifetime        = clientDto.AuthorizationCodeLifetime;
            client.AbsoluteRefreshTokenLifetime     = clientDto.AbsoluteRefreshTokenLifetime;
            client.SlidingRefreshTokenLifetime      = clientDto.SlidingRefreshTokenLifetime;
            client.RefreshTokenUsage                = clientDto.RefreshTokenUsage;
            client.RefreshTokenExpiration           = clientDto.RefreshTokenExpiration;
            client.UpdateAccessTokenClaimsOnRefresh = clientDto.UpdateAccessTokenClaimsOnRefresh;
            client.IncludeJwtId                     = clientDto.IncludeJwtId;
            client.AlwaysSendClientClaims           = clientDto.AlwaysSendClientClaims;
            client.AlwaysIncludeUserClaimsInIdToken = clientDto.AlwaysIncludeUserClaimsInIdToken;
            client.ClientClaimsPrefix               = clientDto.ClientClaimsPrefix;
            client.PairWiseSubjectSalt              = clientDto.PairWiseSubjectSalt;

            var transaction = this.Session.BeginTransaction();

            try
            {
                this.Session.Update(client);

                this.Session.CreateQuery("delete from ClientCorsOrigin where ClientId=:ClientId")
                .SetInt32("ClientId", id)
                .ExecuteUpdate();

                clientDto.AllowedCorsOrigins.ForEach(origin =>
                {
                    ClientCorsOrigin clientCorsOrigin = new ClientCorsOrigin();
                    clientCorsOrigin.ClientId         = client.Id;
                    clientCorsOrigin.Origin           = origin;
                    this.Session.Save(clientCorsOrigin);
                });

                this.Session.CreateQuery("delete from ClientClaim where ClientId=:ClientId")
                .SetInt32("ClientId", id)
                .ExecuteUpdate();

                clientDto.Claims.ForEach(claim =>
                {
                    ClientClaim clientClaim = new ClientClaim();
                    clientClaim.ClientId    = client.Id;
                    clientClaim.Type        = claim.Type;
                    clientClaim.Value       = claim.Value;
                    this.Session.Save(clientClaim);
                });

                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }