private async void AcceptAmazonCredsButton_Clicked(object sender, EventArgs e) { AmazonS3Config config = new AmazonS3Config( AccessID, SecretKey, Region.Name, BucketName, Path); Dictionary <string, string> createParams = config.ToDictionary(); createParams.Add("ProviderKey", CloudStorageProviderType.Name); _cloudStorageProvider = CloudStorageProviderBase.Create( App.AppLogger.Logger, createParams); _cloudProvider = CloudProviders.Instance.AddProvider( ProviderType.AuthenticationType.Amazon, _cloudStorageProvider.TypeName, config.AccessID, config.ToString(), true); CloudProviderResponse <CloudStorageProviderUserBase> getAccountUserResponse = await _cloudStorageProvider.GetAccountUser(); if (getAccountUserResponse.ResponseValue == CloudProviderResponse <CloudStorageProviderUserBase> .Response.Success) { CloudStorageAccountUser = getAccountUserResponse.Result; IsAuthenticated = true; AmazonCredInput.IsVisible = false; } }
private async Task ListFilesFromProvider() { IEnumerable <CloudProvider> providers = CloudProviders.Instance.Providers.Where(cp => cp.ID == _providerID); if (providers.Any()) { CloudStorageProviderBase storageProvider = null; CloudProvider provider = providers.First(); switch (provider.AuthType) { case ProviderType.AuthenticationType.OAuth: { string providerKey = (string)((App)App.Current).GetProviderValue(_providerID, "ProviderKey"); string accessToken = ((App)App.Current).GetCredential(_providerID); Dictionary <string, string> createParams = new Dictionary <string, string>(); createParams.Add("AuthType", "OAuth"); createParams.Add("ProviderKey", providerKey); createParams.Add("AccessToken", accessToken); storageProvider = CloudStorageProviderBase.Create( App.AppLogger.Logger, createParams); break; } case ProviderType.AuthenticationType.Amazon: { string providerKey = (string)((App)App.Current).GetProviderValue(_providerID, "ProviderKey"); string secret = ((App)App.Current).GetCredential(_providerID); JObject s3ConfigJSON = JObject.Parse(secret); AmazonS3Config s3Config = AmazonS3Config.FromJSON(s3ConfigJSON); Dictionary <string, string> createParams = s3Config.ToDictionary(); createParams.Add("ProviderKey", providerKey); storageProvider = CloudStorageProviderBase.Create( App.AppLogger.Logger, createParams); break; } default: { throw new NotSupportedException(String.Format("Cloud provider authentication type '{0}' is not supported.", provider.AuthType)); } } CloudProviderResponse <List <CloudStorageProviderFileBase> > response = await storageProvider.ListFiles(); if (response.ResponseValue == CloudProviderResponse <List <CloudStorageProviderFileBase> > .Response.Success) { CreateTreeNodes(response.Result); } } }
public async Task <bool> CheckCredentialAccessAsync() { Dictionary <string, string> cred = devoctomy.cachy.Framework.Native.Native.PasswordVault.GetCredential(ID); _credentialError = (cred == null); if (!_credentialError) { string secret = cred["Password"]; switch (AuthType) { case ProviderType.AuthenticationType.OAuth: { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("AuthType", "OAuth"); parameters.Add("ProviderKey", ProviderKey); parameters.Add("AccessToken", secret); CloudStorageProviderBase provider = CloudStorageProviderBase.Create( App.AppLogger.Logger, parameters); try { CloudProviderResponse <CloudStorageProviderUserBase> accountUserResponse = await provider.GetAccountUser(); _credentialError = !(accountUserResponse.ResponseValue == CloudProviderResponse <CloudStorageProviderUserBase> .Response.Success); _username = String.Empty; } catch (Exception) { _credentialError = true; } break; } case ProviderType.AuthenticationType.Amazon: { JObject s3ConfigJSON = JObject.Parse(secret); AmazonS3Config s3Config = AmazonS3Config.FromJSON(s3ConfigJSON); Dictionary <string, string> parameters = s3Config.ToDictionary(); parameters.Add("ProviderKey", ProviderKey); CloudStorageProviderBase provider = CloudStorageProviderBase.Create( App.AppLogger.Logger, parameters); try { CloudProviderResponse <CloudStorageProviderUserBase> accountUserResponse = await provider.GetAccountUser(); _credentialError = !(accountUserResponse.ResponseValue == CloudProviderResponse <CloudStorageProviderUserBase> .Response.Success); _username = String.Empty; } catch (Exception) { _credentialError = true; } break; } } } NotifyPropertyChanged("CredentialError"); NotifyPropertyChanged("UserName"); return(_credentialError); }