コード例 #1
0
 private static IEnumerable <AuthService> GetAuthServices()
 {
     return(from KeyElement keyElement in ConsumerConfigurationSection.GetSection().Keys
            where keyElement.Type != KeyElement.KeyType.Default && !string.IsNullOrEmpty(keyElement.ConsumerName)
            group keyElement by keyElement.ConsumerName
            into keyGroup
            let consumerKey = keyGroup.FirstOrDefault(key => key.Type == KeyElement.KeyType.Key)
                              let consumerSecret = keyGroup.FirstOrDefault(key => key.Type == KeyElement.KeyType.Secret)
                                                   select ToAuthService(keyGroup.Key, consumerKey, consumerSecret));
 }
コード例 #2
0
        public bool SaveAuthKeys(List <AuthKey> authKeys)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
            if (!SetupInfo.IsVisibleSettings(ManagementType.ThirdPartyAuthorization.ToString()))
            {
                throw new BillingException(Resource.ErrorNotAllowedOption, "ThirdPartyAuthorization");
            }

            var changed = false;

            var mapKeys = new Dictionary <string, List <KeyElement> >();

            foreach (var authKey in authKeys.Where(authKey => KeyStorage.Get(authKey.Name) != authKey.Value))
            {
                var keyElement = ConsumerConfigurationSection.GetSection().Keys.GetKey(authKey.Name);

                if (keyElement != null && Providers.ContainsKey(keyElement.ConsumerName))
                {
                    RemoveOldNumberFromTwilio(Providers[keyElement.ConsumerName]);

                    if (!string.IsNullOrEmpty(authKey.Value))
                    {
                        if (!mapKeys.ContainsKey(keyElement.ConsumerName))
                        {
                            mapKeys.Add(keyElement.ConsumerName, new List <KeyElement>());
                        }
                        mapKeys[keyElement.ConsumerName].Add(keyElement);
                    }
                }


                KeyStorage.Set(authKey.Name, authKey.Value);
                changed = true;
            }

            foreach (var providerKeys in mapKeys)
            {
                if (!Providers[providerKeys.Key].ValidateKeys())
                {
                    foreach (var providerKey in providerKeys.Value)
                    {
                        KeyStorage.Set(providerKey.Name, null);
                    }
                    throw new ArgumentException(Resource.ErrorBadKeys);
                }
            }

            if (changed)
            {
                MessageService.Send(HttpContext.Current.Request, MessageAction.AuthorizationKeysSetting);
            }

            return(changed);
        }
コード例 #3
0
        private static IAssociatedTokenManager GetTokenManager(string consumerKey, string consumerSecret)
        {
            IAssociatedTokenManager tokenManager = null;
            var section = ConsumerConfigurationSection.GetSection();

            if (section != null && !string.IsNullOrEmpty(section.ConnectionString))
            {
                tokenManager = new DbTokenManager(KeyStorage.Get(consumerKey), KeyStorage.Get(consumerSecret),
                                                  "auth_tokens",
                                                  ConfigurationManager.ConnectionStrings[section.ConnectionString]);
            }
            else
            {
                //For testing return the inmemorytokenmanager
                tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
            }

            return(tokenManager);
        }