private async Task AddApiResources()
    {
        var apiResource = new ApiResource(_testData.ApiResource1Id, "NewApiResource1");

        apiResource.Description = nameof(apiResource.Description);
        apiResource.DisplayName = nameof(apiResource.DisplayName);

        apiResource.AddScope(nameof(ApiResourceScope.Scope));
        apiResource.AddUserClaim(nameof(ApiResourceClaim.Type));
        apiResource.AddSecret(nameof(ApiResourceSecret.Value));

        await _apiResourceRepository.InsertAsync(apiResource);

        await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource2"));

        await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource3"));

        var apiResource2 = new ApiResource(_guidGenerator.Create(), "Test-ApiResource-Name-1")
        {
            Enabled     = true,
            Description = "Test-ApiResource-Description-1",
            DisplayName = "Test-ApiResource-DisplayName-1"
        };

        apiResource2.AddSecret("secret".Sha256());
        apiResource2.AddScope("Test-ApiResource-ApiScope-Name-1");
        apiResource2.AddScope("Test-ApiResource-ApiScope-DisplayName-1");
        apiResource2.AddUserClaim("Test-ApiResource-Claim-Type-1");

        await _apiResourceRepository.InsertAsync(apiResource2);
    }
        private async Task <ApiResource> CreateApiResourceAsync(string name, IEnumerable <string> claims)
        {
            ApiResource apiResource = await _apiResourceRepository.FindByNameAsync(name);

            if (apiResource == null)
            {
                apiResource = await _apiResourceRepository.InsertAsync(
                    new ApiResource(
                        _guidGenerator.Create(),
                        name,
                        name + " API"
                        ),
                    autoSave : true
                    );
            }

            foreach (string claim in claims)
            {
                if (apiResource.FindClaim(claim) == null)
                {
                    apiResource.AddUserClaim(claim);
                }
            }

            return(await _apiResourceRepository.UpdateAsync(apiResource));
        }
Пример #3
0
        public virtual async Task <ApiResourceDto> CreateAsync(ApiResourceCreateDto apiResourceCreate)
        {
            var apiResource = new ApiResource(GuidGenerator.Create(), apiResourceCreate.Name,
                                              apiResourceCreate.DisplayName, apiResourceCreate.Description);

            apiResource.Enabled = apiResourceCreate.Enabled;
            foreach (var userClaim in apiResourceCreate.UserClaims)
            {
                apiResource.AddUserClaim(userClaim.Type);
            }
            apiResource = await ApiResourceRepository.InsertAsync(apiResource);

            return(ObjectMapper.Map <ApiResource, ApiResourceDto>(apiResource));
        }
        private void AddApiResources()
        {
            var apiResource = new ApiResource(_guidGenerator.Create(), "Test-ApiResource-Name-1")
            {
                Enabled     = true,
                Description = "Test-ApiResource-Description-1",
                DisplayName = "Test-ApiResource-DisplayName-1"
            };

            apiResource.AddSecret("secret".Sha256());
            apiResource.AddScope("Test-ApiResource-ApiScope-Name-1", "Test-ApiResource-ApiScope-DisplayName-1");
            apiResource.AddUserClaim("Test-ApiResource-Claim-Type-1");

            _apiResourceRepository.Insert(apiResource);
        }
Пример #5
0
        private async Task AddApiResources()
        {
            var apiResource = new ApiResource(_guidGenerator.Create(), "Test-ApiResource-Name-1")
            {
                Enabled     = true,
                Description = "Test-ApiResource-Description-1",
                DisplayName = "Test-ApiResource-DisplayName-1"
            };

            apiResource.AddSecret("secret".Sha256());
            apiResource.AddScope("Test-ApiResource-ApiScope-Name-1", "Test-ApiResource-ApiScope-DisplayName-1");
            apiResource.AddUserClaim("Test-ApiResource-Claim-Type-1");

            await _apiResourceRepository.InsertAsync(apiResource).ConfigureAwait(false);
        }
        public virtual async Task <ApiResourceDto> CreateAsync(ApiResourceCreateDto apiResourceCreate)
        {
            var apiResourceExists = await ApiResourceRepository.CheckNameExistAsync(apiResourceCreate.Name);

            if (apiResourceExists)
            {
                throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.ApiResourceNameExisted, apiResourceCreate.Name]);
            }
            var apiResource = new ApiResource(GuidGenerator.Create(), apiResourceCreate.Name,
                                              apiResourceCreate.DisplayName, apiResourceCreate.Description)
            {
                Enabled = apiResourceCreate.Enabled
            };

            foreach (var userClaim in apiResourceCreate.UserClaims)
            {
                apiResource.AddUserClaim(userClaim.Type);
            }
            apiResource = await ApiResourceRepository.InsertAsync(apiResource);

            return(ObjectMapper.Map <ApiResource, ApiResourceDto>(apiResource));
        }