Exemple #1
0
        public async Task <string> CreateAsync(ApplicationParam model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var entity = await _manager.FindByClientIdAsync(model.ClientId);

            if (entity == null)
            {
                // create new entity
                var newEntity = new OpenIddictEntityFrameworkCoreApplication
                {
                    ClientId    = model.ClientId,
                    DisplayName = model.DisplayName,
                    Type        = model.Type
                };

                HandleCustomProperties(model, newEntity);

                await _manager.CreateAsync(newEntity, model.ClientSecret);

                return(newEntity.Id);
            }

            // update existing entity
            model.Id = entity.Id;
            await UpdateAsync(model);

            return(entity.Id);
        }
Exemple #2
0
 private static void HandleCustomProperties(
     ApplicationParam model,
     OpenIddictEntityFrameworkCoreApplication entity
     )
 {
     entity.ConsentType            = model.RequireConsent ? ConsentTypes.Explicit : ConsentTypes.Implicit;
     entity.Permissions            = JsonSerializer.Serialize(model.Permissions);
     entity.RedirectUris           = JsonSerializer.Serialize(model.RedirectUris);
     entity.PostLogoutRedirectUris = JsonSerializer.Serialize(model.PostLogoutRedirectUris);
     entity.Requirements           = model.RequirePkce ? JsonSerializer.Serialize(new List <string> {
         Requirements.Features.ProofKeyForCodeExchange
     }) : null;
 }
Exemple #3
0
        public async Task UpdateAsync(ApplicationParam model)
        {
            if (string.IsNullOrWhiteSpace(model.Id))
            {
                throw new ArgumentNullException(nameof(model.Id));
            }

            var entity = await _manager.FindByIdAsync(model.Id);

            SimpleMapper.Map <ApplicationParam, OpenIddictEntityFrameworkCoreApplication>(model, entity);

            HandleCustomProperties(model, entity);

            await _manager.UpdateAsync(entity, entity.ClientSecret);
        }