internal async Task <PNResult <PNAccessManagerGrantResult> > GrantAccess(string[] channels, string[] channelGroups, string[] authKeys, bool read, bool write, bool delete, bool manage, long ttl, Dictionary <string, object> externalQueryParam) { if (string.IsNullOrEmpty(config.SecretKey) || string.IsNullOrEmpty(config.SecretKey.Trim()) || config.SecretKey.Length <= 0) { throw new MissingMemberException("Invalid secret key"); } PNResult <PNAccessManagerGrantResult> ret = new PNResult <PNAccessManagerGrantResult>(); List <string> channelList = new List <string>(); List <string> channelGroupList = new List <string>(); List <string> authList = new List <string>(); if (channels != null && channels.Length > 0) { channelList = new List <string>(channels); channelList = channelList.Where(ch => !string.IsNullOrEmpty(ch) && ch.Trim().Length > 0).Distinct <string>().ToList(); } if (channelGroups != null && channelGroups.Length > 0) { channelGroupList = new List <string>(channelGroups); channelGroupList = channelGroupList.Where(cg => !string.IsNullOrEmpty(cg) && cg.Trim().Length > 0).Distinct <string>().ToList(); } if (authKeys != null && authKeys.Length > 0) { authList = new List <string>(authKeys); authList = authList.Where(auth => !string.IsNullOrEmpty(auth) && auth.Trim().Length > 0).Distinct <string>().ToList(); } string channelsCommaDelimited = string.Join(",", channelList.ToArray().OrderBy(x => x).ToArray()); string channelGroupsCommaDelimited = string.Join(",", channelGroupList.ToArray().OrderBy(x => x).ToArray()); string authKeysCommaDelimited = string.Join(",", authList.ToArray().OrderBy(x => x).ToArray()); IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : ""); Uri request = urlBuilder.BuildGrantV2AccessRequest("GET", "", channelsCommaDelimited, channelGroupsCommaDelimited, authKeysCommaDelimited, read, write, delete, manage, ttl, externalQueryParam); RequestState <PNAccessManagerGrantResult> requestState = new RequestState <PNAccessManagerGrantResult>(); requestState.Channels = channels; requestState.ChannelGroups = channelGroups; requestState.ResponseType = PNOperationType.PNAccessManagerGrant; requestState.Reconnect = false; requestState.EndPointOperation = this; Tuple <string, PNStatus> JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false).ConfigureAwait(false); ret.Status = JsonAndStatusTuple.Item2; string json = JsonAndStatusTuple.Item1; if (!string.IsNullOrEmpty(json)) { List <object> resultList = ProcessJsonResponse(requestState, json); if (resultList != null && resultList.Count > 0) { ResponseBuilder responseBuilder = new ResponseBuilder(config, jsonLibrary, pubnubLog); PNAccessManagerGrantResult responseResult = responseBuilder.JsonToObject <PNAccessManagerGrantResult>(resultList, true); if (responseResult != null) { ret.Result = responseResult; } } } return(ret); }
internal async Task <PNResult <PNAccessManagerGrantResult> > GrantAccess() { if (string.IsNullOrEmpty(config.SecretKey) || string.IsNullOrEmpty(config.SecretKey.Trim()) || config.SecretKey.Length <= 0) { throw new MissingMemberException("Invalid secret key"); } PNResult <PNAccessManagerGrantResult> ret = new PNResult <PNAccessManagerGrantResult>(); List <string> channelList = new List <string>(); List <string> channelGroupList = new List <string>(); List <string> uuidList = new List <string>(); List <string> authList = new List <string>(); if (this.pubnubChannelNames != null && this.pubnubChannelNames.Length > 0) { channelList = new List <string>(this.pubnubChannelNames); channelList = channelList.Where(ch => !string.IsNullOrEmpty(ch) && ch.Trim().Length > 0).Distinct <string>().ToList(); } if (this.pubnubChannelGroupNames != null && this.pubnubChannelGroupNames.Length > 0) { channelGroupList = new List <string>(this.pubnubChannelGroupNames); channelGroupList = channelGroupList.Where(cg => !string.IsNullOrEmpty(cg) && cg.Trim().Length > 0).Distinct <string>().ToList(); } if (this.pubnubTargetUuids != null && this.pubnubTargetUuids.Length > 0) { uuidList = new List <string>(this.pubnubTargetUuids); uuidList = uuidList.Where(uuid => !string.IsNullOrEmpty(uuid) && uuid.Trim().Length > 0).Distinct().ToList(); } if (this.pamAuthenticationKeys != null && this.pamAuthenticationKeys.Length > 0) { authList = new List <string>(this.pamAuthenticationKeys); authList = authList.Where(auth => !string.IsNullOrEmpty(auth) && auth.Trim().Length > 0).Distinct <string>().ToList(); } string channelsCommaDelimited = string.Join(",", channelList.OrderBy(x => x).ToArray()); string channelGroupsCommaDelimited = string.Join(",", channelGroupList.OrderBy(x => x).ToArray()); string targetUuidsCommaDelimited = string.Join(",", uuidList.OrderBy(x => x).ToArray()); string authKeysCommaDelimited = string.Join(",", authList.OrderBy(x => x).ToArray()); IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : ""); Uri request = urlBuilder.BuildGrantV2AccessRequest("GET", "", channelsCommaDelimited, channelGroupsCommaDelimited, targetUuidsCommaDelimited, authKeysCommaDelimited, this.grantRead, this.grantWrite, this.grantDelete, this.grantManage, this.grantGet, this.grantUpdate, this.grantJoin, this.grantTTL, this.queryParam); RequestState <PNAccessManagerGrantResult> requestState = new RequestState <PNAccessManagerGrantResult>(); requestState.Channels = this.pubnubChannelNames; requestState.ChannelGroups = this.pubnubChannelGroupNames; requestState.ResponseType = PNOperationType.PNAccessManagerGrant; requestState.Reconnect = false; requestState.EndPointOperation = this; Tuple <string, PNStatus> JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false).ConfigureAwait(false); ret.Status = JsonAndStatusTuple.Item2; string json = JsonAndStatusTuple.Item1; if (!string.IsNullOrEmpty(json)) { List <object> resultList = ProcessJsonResponse(requestState, json); if (resultList != null && resultList.Count > 0) { ResponseBuilder responseBuilder = new ResponseBuilder(config, jsonLibrary, pubnubLog); PNAccessManagerGrantResult responseResult = responseBuilder.JsonToObject <PNAccessManagerGrantResult>(resultList, true); if (responseResult != null) { ret.Result = responseResult; } } } return(ret); }