예제 #1
0
        /// <summary>
        /// Retrieves a list of all client applications.
        /// </summary>
        /// <param name="request">Specifies criteria to use when querying clients.</param>
        /// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
        /// <returns>An <see cref="IPagedList{Client}"/> containing the clients.</returns>
        public Task <IPagedList <Client> > GetAllAsync(GetClientsRequest request, PaginationInfo pagination)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (pagination == null)
            {
                throw new ArgumentNullException(nameof(pagination));
            }

            var queryStrings = new Dictionary <string, string>
            {
                { "fields", request.Fields },
                { "include_fields", request.IncludeFields?.ToString().ToLower() },
                { "is_global", request.IsGlobal?.ToString().ToLower() },
                { "is_first_party", request.IsFirstParty?.ToString().ToLower() },
                { "page", pagination.PageNo.ToString() },
                { "per_page", pagination.PerPage.ToString() },
                { "include_totals", pagination.IncludeTotals.ToString().ToLower() },
            };

            if (request.AppType != null)
            {
                queryStrings.Add("app_type", string.Join(",", request.AppType.Select(ToEnumString)));
            }

            return(Connection.GetAsync <IPagedList <Client> >("clients", null, queryStrings, null, new PagedListConverter <Client>("clients")));
        }
예제 #2
0
        public override async Task ProcessAsync(Auth0ResourceTemplate template)
        {
            using var managementClient = await _managementApiClientFactory.CreateAsync();

            var client = _converter.Convert(template);

            var getClientsRequest = new GetClientsRequest
            {
                IsGlobal = false, IncludeFields = true, Fields = "name,client_id"
            };
            var results = managementClient.Clients.GetAllAsync(getClientsRequest, Reporter);

            FixIllegalOptions(client);

            var matchingClient = await results.FirstOrDefaultAsync(x => string.Equals(x.Name, client.Name));

            if (matchingClient == null)
            {
                var createRequest = Reflectorisor.CopyMembers <Client, ClientCreateRequest>(client);
                await Create(
                    async() => await managementClient.Clients.CreateAsync(createRequest),
                    request => request.ClientId,
                    client.Name);
            }
            else
            {
                var updateRequest = Reflectorisor.CopyMembers <Client, ClientUpdateRequest>(client);
                await Update(
                    async() => await managementClient.Clients.UpdateAsync(matchingClient.ClientId, updateRequest),
                    matchingClient.ClientId,
                    client.Name
                    );
            }
        }
예제 #3
0
        private async Task SetLoginPage(BanjoPage page)
        {
            using var managementClient = await _managementApiClientFactory.CreateAsync();

            var getClientsRequest = new GetClientsRequest
            {
                IsGlobal = true, Fields = "client_id,name", IncludeFields = true
            };
            var globalClients = managementClient.Clients.GetAllAsync(getClientsRequest, Reporter);
            var globalClient  = await globalClients.FirstOrDefaultAsync();

            if (globalClient == null)
            {
                throw new Auth0ResourceNotFoundException("No global client found.");
            }

            var clientUpdateRequest = new ClientUpdateRequest()
            {
                CustomLoginPage = page.Html, IsCustomLoginPageOn = true
            };

            await Update(async() =>
            {
                await managementClient.Clients.UpdateAsync(globalClient.ClientId, clientUpdateRequest);
                return(page);
            },
                         page.PageType.ToString());
        }
예제 #4
0
        public override async Task Preprocess(Auth0ResourceTemplate template)
        {
            //Connection templates have a property enabled_clients_match_conditions that contains regexes or string
            //literals of client names that the connection should be associated with.
            //This preprocessing step looks up all the deployed clients and

            var matchConditions = new JsonSerializer().Deserialize <ConnectionClientMatchConditions>(
                new JTokenReader(template.Template))
                                  ?.EnabledClientsMatchConditions?.ToList() ?? new List <string>();

            if (matchConditions.Count == 0)
            {
                template.Preprocessed = true;
                return;
            }

            using var managementClient = await _managementApiClientFactory.CreateAsync();

            var getClientsRequest = new GetClientsRequest()
            {
                IsGlobal = false, IncludeFields = true, Fields = "name,client_id"
            };
            var clients = await managementClient.Clients.GetAllAsync(getClientsRequest, new PaginationInfo());

            var matchConditionsRegexes = matchConditions.Select(x => new Regex(x));
            var matchingClientIds      = clients.Where(x =>
                                                       //check for exact string match OR regex match
                                                       matchConditionsRegexes.Any(regex => string.Equals(regex.ToString(), x.Name) || regex.IsMatch(x.Name))
                                                       ).Select(x => (object)new JValue(x.ClientId)).ToList();

            if (!(template.Template is JObject t))
            {
                throw new InvalidOperationException(
                          $"{Type.Name} template {template.Filename} processed type is not of type JObject." +
                          $" Found {template.Template.GetType().Name}");
            }

            //add the enabled_clients
            t.Add("enabled_clients", new JArray(matchingClientIds.ToArray()));

            //remove the enabled_clients_match_conditions
            t.Remove("enabled_clients_match_conditions");

            if (_args.CurrentValue.DryRun)
            {
                Reporter.Warn(
                    "Dry-run flag is set. Any clients that do not exist but that will be created by " +
                    "these templates when run without the dry-run flag may not be found and included in this " +
                    "connections\' enabled_clients list. The complete list of matching clients will be found when " +
                    "run without the dry-run flag.");
            }

            template.Preprocessed = true;
        }
예제 #5
0
        public override async Task ProcessAsync(Auth0ResourceTemplate template)
        {
            //get the client that matches the ClientGrant.ClientId so we get Client.Id

            using var managementClient = await _managementApiClientFactory.CreateAsync();

            var templatedGrant = _converter.Convert(template);

            var getClientsRequest = new GetClientsRequest
            {
                IsGlobal = false, IncludeFields = true, Fields = "name,client_id"
            };
            var allClients = await managementClient.Clients.GetAllAsync(getClientsRequest, new PaginationInfo());

            var matchingClient = allClients.FirstOrDefault(x => x.Name == templatedGrant.ClientId);

            if (matchingClient == null)
            {
                throw new Auth0ResourceNotFoundException($"No {ResourceType.Clients.Name} exists with name " +
                                                         $"{templatedGrant.ClientId}. Cannot create/update " +
                                                         $"{ResourceType.ClientGrants.Name} {template.Filename}");
            }

            templatedGrant.ClientId = matchingClient.ClientId;

            var allGrants     = managementClient.ClientGrants.GetAllAsync(new GetClientGrantsRequest(), Reporter);
            var existingGrant = await allGrants.FirstOrDefaultAsync(
                x => string.Equals(x.ClientId, templatedGrant.ClientId) &&
                string.Equals(x.Audience, templatedGrant.Audience));

            if (existingGrant == null)
            {
                var createRequest = Reflectorisor.CopyMembers <ClientGrant, ClientGrantCreateRequest>(templatedGrant);
                await Create(
                    async() => await managementClient.ClientGrants.CreateAsync(createRequest),
                    request => request.Id,
                    $"[{matchingClient.Name}|{createRequest.Audience}]");
            }
            else
            {
                var updateRequest = Reflectorisor.CopyMembers <ClientGrant, ClientGrantUpdateRequest>(templatedGrant);
                await Update(
                    async() => await managementClient.ClientGrants.UpdateAsync(existingGrant.Id, updateRequest),
                    existingGrant.Id,
                    $"[{matchingClient.Name}|{existingGrant.Audience}]");
            }
        }
예제 #6
0
        public async Task <IActionResult> GetAll([FromQuery] GetClientsRequest request)
        {
            try
            {
                var clients = await clientService.GetAllAsync();

                var response = new GetClientsResponse
                {
                    Items = mapper.Map <List <ClientDto> >(clients),
                    Total = clients.Count
                };

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(ExceptionResult(e));
            }
        }
 public static IAsyncEnumerable <Client> GetAllAsync(this ClientsClient client, GetClientsRequest request, IReporter reporter = null)
 {
     return(GetAllAsyncInternal(page => client.GetAllAsync(request, page), "clients", reporter));
 }
예제 #8
0
 public async Task <GetClientsResponse> Browse(GetClientsRequest request = null)
 {
     request = request ?? new GetClientsRequest();
     return(await Client.Execute <GetClientsRequest, GetClientsResponse>(request));
 }