public async void OnNavigateTo(View view, object parameter) { ((App)App.Current).AndroidSetSoftInputMode(true); string continueResponseString = await AuthenticationHelpers.ContinueOAuthAuthentication(_providerID, _sessionID); if (!String.IsNullOrEmpty(continueResponseString)) { Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("ProviderID", _providerID); parameters.Add("AuthResponse", continueResponseString); parameters.Add("RSA", _rsa); App.Controller.ClosePopup(parameters); } else { await App.Controller.MainPageInstance.DisplayAlert("Authentication Error", String.Format("An error occurred whilst authenticating with '{0}'. Please try again later.", _providerID), "OK"); App.Controller.ClosePopup(null); } }
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; } } }