示例#1
0
        public async Task <bool> RetrieveAuthenticationFromRedirectAsync(Uri uri)
        {
            bool authenticationFound = false;

            if (string.Equals(uri.Authority, this.RedirectUrl.Authority, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(uri.AbsolutePath, this.RedirectUrl.AbsolutePath, StringComparison.OrdinalIgnoreCase))
            {
                DesignTimeAuthenticationViewModel.CheckAuthenticationErrors(uri);

                string[] parameters = uri.Fragment.TrimStart('#').Split('&');

                this.Authentication.AccessToken  = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "access_token=");
                this.Authentication.RefreshToken = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "refresh_token=");
                this.Authentication.InstanceUrl  = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "instance_url=");

                try
                {
                    string id = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "id=");
                    await this.RetrieveIdInfoAsync(id);
                }
                catch (Exception)
                {
                    this.Authentication.AccessToken  = null;
                    this.Authentication.RefreshToken = null;
                    this.Authentication.InstanceUrl  = null;

                    throw;
                }

                authenticationFound = true;
            }

            return(authenticationFound);
        }
        public AuthenticateRedirectHost(DesignTimeAuthenticationViewModel authenticationViewModel)
        {
            this.InitializeComponent();

            this.DataContext = authenticationViewModel;

            this.browser.Navigating += browser_Navigating;
            this.browser.Navigate(authenticationViewModel.AuthorizeUrl);
        }
示例#3
0
        private static void CheckAuthenticationErrors(Uri uri)
        {
            string[] parameters = uri.Query.TrimStart('?').Split('&');
            string   error      = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "error=");

            if (error != null)
            {
                string errorDescription = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "error_description=");

                // In the unexpected case when there is no error description, use the error code.
                string exceptionMessage = errorDescription == null ? error : errorDescription;

                throw new InvalidOperationException(exceptionMessage);
            }
        }
        private void InitializePages()
        {
            this.designTimeAuthenticationViewModel = new DesignTimeAuthenticationViewModel();
            this.designTimeAuthenticationViewModel.PageLeaving += DesignTimeAuthenticationViewModel_PageLeaving;
            this.runtimeAuthenticationTypeViewModel = new RuntimeAuthenticationTypeViewModel();
            this.runtimeAuthenticationConfigViewModel = new RuntimeAuthenticationConfigViewModel(
                () => this.designTimeAuthenticationViewModel.Authentication?.MyDomain);
            this.runtimeAuthenticationConfigViewModel.RuntimeAuthStrategy = this.runtimeAuthenticationTypeViewModel.RuntimeAuthStrategy;
            this.objectSelectionViewModel = new ObjectSelectionViewModel();

            this.Pages.Add(this.designTimeAuthenticationViewModel);
            this.Pages.Add(this.runtimeAuthenticationTypeViewModel);
            this.Pages.Add(this.runtimeAuthenticationConfigViewModel);
            this.Pages.Add(this.objectSelectionViewModel);

            // Some logic within the view models depend on the Wizard.  This logic must be invoked after the pages have
            // been added to the wizard in order for the Wizard property to be available on the ConnectedServiceWizardPage.
            if (this.Context.IsUpdating)
            {
                this.RestoreAuthenticationSettings();
            }

            foreach (SalesforceConnectedServiceWizardPage page in this.Pages)
            {
                page.PropertyChanged += this.PageViewModel_PropertyChanged;
            }
        }
        public DesignTimeAuthenticationPage(DesignTimeAuthenticationViewModel designTimeAuthenticationViewModel)
        {
            this.InitializeComponent();

            this.DataContext = designTimeAuthenticationViewModel;
        }