コード例 #1
0
        public async Task <IActionResult> PostScope(int id, [FromBody] ApiScopeApiDto apiScopeApi)
        {
            var apiScope = apiScopeApi.ToApiResourceApiModel <ApiScopesDto>();

            apiScope.ApiResourceId = id;

            await _apiResourceService.GetApiResourceAsync(apiScope.ApiResourceId);

            await _apiResourceService.AddApiScopeAsync(apiScope);

            return(Ok());
        }
コード例 #2
0
        public async Task CreateResourceScope(int id, string name, string display, string description)
        {
            var userClaims = new List <string>()
            {
                "claim1",
                "claim2",
                "claim3"
            };
            var req = new ApiScopeApiDto(0, name, display, description, true, true, true, userClaims);

            var result = await apiKYC.CreateResourceScope(id, req);

            Assert.True(result);
        }
コード例 #3
0
        public async Task <bool> CreateResourceScope(int?id, ApiScopeApiDto scope)
        {
            // discover endpoints from metadata
            var client = new HttpClient();
            var disco  = await client.GetDiscoveryDocumentAsync(IdentityEndpoint.Discovery);

            if (disco.IsError)
            {
                return(false);
            }

            // request token
            var req = new PasswordTokenRequest
            {
                Address = disco.TokenEndpoint,

                ClientId     = IdentityEndpoint.ClientID,
                ClientSecret = IdentityEndpoint.Secret,
                Scope        = IdentityEndpoint.Scopes,
                UserName     = IdentityEndpoint.UserName,
                Password     = IdentityEndpoint.Password
            };
            var tokenResponse = await client.RequestPasswordTokenAsync(req);

            if (tokenResponse.IsError)
            {
                return(false);
            }

            var apiClient = new HttpClient();

            apiClient.SetBearerToken(tokenResponse.AccessToken);

            var dataJson      = JsonSerializer.Serialize(scope);
            var stringContent = new StringContent(dataJson, Encoding.UTF8, "application/json");

            var response = await apiClient.PostAsync(IdentityEndpoint.ResourceUri + $"/{id.Value}/Scopes", stringContent);

            return(response.IsSuccessStatusCode);
        }
コード例 #4
0
        public async Task <IActionResult> PostScope([FromBody] ApiScopeApiDto apiScopeApi)
        {
            var apiScope = apiScopeApi.ToApiScopeApiModel <ApiScopeDto>();

            if (!apiScope.Id.Equals(default))