Esempio n. 1
0
        private async void ReauthenticateCloudProvider()
        {
            devoctomy.cachy.Framework.Native.Native.WebUtility.ClearInAppBrowserCache();
            Dictionary <string, object> parameters = await AuthenticationHelpers.BeginOAuthAuthentication(SelectedCloudProvider.ProviderKey);

            if (parameters != null)
            {
                App.Controller.ShowPopup("settings.oauth",
                                         parameters.ToArray());
            }
            else
            {
                await App.Controller.MainPageInstance.DisplayAlert("Authentication Failure",
                                                                   "Failed to start the authentication process, please try again later.",
                                                                   "OK");
            }
        }
Esempio n. 2
0
        public async void ProviderLoginAction(object parameter)
        {
            App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Information, "ProviderLoginAction command invoked.");
            IsConnecting = true;
            switch (CloudStorageProviderType.AuthType)
            {
            case ProviderType.AuthenticationType.OAuth:
            {
                devoctomy.cachy.Framework.Native.Native.WebUtility.ClearInAppBrowserCache();
                Dictionary <string, object> parameters = await AuthenticationHelpers.BeginOAuthAuthentication(CloudStorageProviderType.Name);

                if (parameters != null)
                {
                    App.Controller.ShowPopup("createvault.oauth",
                                             parameters.ToArray());
                }
                else
                {
                    await App.Controller.MainPageInstance.DisplayAlert("Authentication Failure",
                                                                       "Failed to start the authentication process, please try again later.",
                                                                       "OK");
                }
                break;
            }

            case ProviderType.AuthenticationType.Amazon:
            {
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                AmazonS3Config config = new AmazonS3Config(
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    "cachy");
                parameters.Add("S3Config", config);
                App.Controller.ShowPopup("createvault.s3setup",
                                         parameters.ToArray());
                break;
            }
            }
        }
Esempio n. 3
0
        private async void SetupCloudProvider()
        {
            if (CloudStorageProviderType == null)
            {
                return;
            }

            switch (CloudStorageProviderType.AuthType)
            {
            case ProviderType.AuthenticationType.OAuth:
            {
                try
                {
                    IsConnecting = true;
                    _forcePage   = CloudProviderPage;
                    devoctomy.cachy.Framework.Native.Native.WebUtility.ClearInAppBrowserCache();

                    Dictionary <string, object> beginParams = await AuthenticationHelpers.BeginOAuthAuthentication(CloudStorageProviderType.Name);

                    string sessionID    = (string)beginParams["SessionID"];
                    Uri    authoriseURI = null;
                    switch (CloudStorageProviderType.Name)
                    {
                    case "Dropbox":
                    {
                        string redirectURI = Uri.EscapeDataString("https://cachywebfunctions20190202044830.azurewebsites.net/api/DropboxOAuthRedirect");
                        string uri         = String.Format(
                            "https://www.dropbox.com/oauth2/authorize?response_type=code&client_id={0}&redirect_uri={1}&state={2}",
                            "bllblee6oqr9q22",
                            redirectURI,
                            sessionID);
                        authoriseURI = new Uri(uri);
                        break;
                    }

                    case "OneDrive":
                    {
                        string redirectURI = Uri.EscapeDataString("https://cachywebfunctions20190202044830.azurewebsites.net/api/OneDriveOAuthRedirect");
                        string uri         = String.Format(
                            "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?response_type=code&client_id={0}&scope={1}&redirect_uri={2}&state={3}",
                            "28cb64d4-f3a2-42db-8889-b760e2163496",
                            Uri.EscapeDataString("https://graph.microsoft.com/Files.ReadWrite.AppFolder,https://graph.microsoft.com/User.Read"),
                            redirectURI,
                            sessionID);
                        authoriseURI = new Uri(uri);
                        break;
                    }

                    default:
                    {
                        //Uknown OAuth cloud provider type!
                        return;
                    }
                    }
                    OAuthWebView.Source    = authoriseURI;
                    OAuthWebView.IsVisible = true;
                    string continueResponseString = await AuthenticationHelpers.ContinueOAuthAuthentication(CloudStorageProviderType.Name, sessionID);

                    Dictionary <string, object> continueParameters = new Dictionary <string, object>();
                    continueParameters.Add("ProviderID", CloudStorageProviderType.Name);
                    continueParameters.Add("AuthResponse", continueResponseString);
                    continueParameters.Add("RSA", beginParams["RSA"]);

                    string accessToken = AuthenticationHelpers.CompleteOAuthAutentication(continueParameters);

                    Dictionary <string, string> createParams = new Dictionary <string, string>();
                    createParams.Add("AuthType", "OAuth");
                    createParams.Add("ProviderKey", (string)continueParameters["ProviderID"]);
                    createParams.Add("AccessToken", accessToken);
                    _cloudStorageProvider = CloudStorageProviderBase.Create(
                        App.AppLogger.Logger,
                        createParams);

                    CloudProviderResponse <CloudStorageProviderUserBase> getAccountUserResponse = await _cloudStorageProvider.GetAccountUser();

                    if (getAccountUserResponse.ResponseValue == CloudProviderResponse <CloudStorageProviderUserBase> .Response.Success)
                    {
                        CloudStorageAccountUser = getAccountUserResponse.Result;

                        switch (CloudStorageProviderType.AuthType)
                        {
                        case ProviderType.AuthenticationType.OAuth:
                        {
                            _cloudProvider = CloudProviders.Instance.AddProvider(
                                ProviderType.AuthenticationType.OAuth,
                                _cloudStorageProvider.TypeName,
                                CloudStorageAccountUser.Email,
                                accessToken,
                                true);
                            break;
                        }
                        }

                        IsAuthenticated = true;
                    }
                    else
                    {
                        CloudStorageAccountUser = null;
                        IsAuthenticated         = false;
                    }
                }
                catch (Exception ex)
                {
                    //log exception here
                }
                finally
                {
                    IsConnecting           = false;
                    _forcePage             = null;
                    OAuthWebView.IsVisible = false;
                }

                break;
            }

            case ProviderType.AuthenticationType.Amazon:
            {
                AmazonCredInput.IsVisible = true;
                break;
            }
            }
        }