public override async Task <WizardNavigationResult> OnPageLeavingAsync(WizardLeavingArgs args) { WizardNavigationResult result; using (this.Wizard.Context.StartBusyIndicator(Resources.DesignTimeAuthenticationViewModel_AuthenticatingProgress)) { string error = null; if (this.Authentication.RefreshToken == null) { // New identity or a existing identity w/no refresh token error = this.AuthenticateUser(); if (error == null && this.Authentication.EnvironmentType == EnvironmentType.Custom) { UserSettings.AddToTopOfMruList(this.Wizard.UserSettings.MruMyDomains, this.Authentication.MyDomain.ToString()); } } else if (this.Authentication.AccessToken == null) { // Existing identity w/no access token try { await AuthenticationHelper.RefreshAccessTokenAsync(this.Authentication); } catch (ForceException ex) { if (ex.Error == Error.InvalidGrant) // Expired refresh token { this.Authentication.RefreshToken = null; error = this.AuthenticateUser(); } else { error = ex.Message; } } } // else - Existing identity w/access and refresh token if (error == null) { UserSettings.AddToTopOfMruList(this.Wizard.UserSettings.MruDesignTimeAuthentications, this.Authentication); result = WizardNavigationResult.Success; if (this.PageLeaving != null) { this.PageLeaving(this, EventArgs.Empty); } } else { result = new WizardNavigationResult() { ErrorMessage = error, ShowMessageBoxOnFailure = true }; } } return(result); }
public override async Task<WizardNavigationResult> OnPageLeavingAsync(WizardLeavingArgs args) { WizardNavigationResult result; using (this.Wizard.Context.StartBusyIndicator(Resources.DesignTimeAuthenticationViewModel_AuthenticatingProgress)) { string error = null; if (this.Authentication.RefreshToken == null) { // New identity or a existing identity w/no refresh token error = this.AuthenticateUser(); if (error == null && this.Authentication.EnvironmentType == EnvironmentType.Custom) { UserSettings.AddToTopOfMruList(this.Wizard.UserSettings.MruMyDomains, this.Authentication.MyDomain.ToString()); } } else if (this.Authentication.AccessToken == null) { // Existing identity w/no access token try { await AuthenticationHelper.RefreshAccessTokenAsync(this.Authentication); } catch (ForceException ex) { if (ex.Error == Error.InvalidGrant) // Expired refresh token { this.Authentication.RefreshToken = null; error = this.AuthenticateUser(); } else { error = ex.Message; } } } // else - Existing identity w/access and refresh token if (error == null) { UserSettings.AddToTopOfMruList(this.Wizard.UserSettings.MruDesignTimeAuthentications, this.Authentication); result = WizardNavigationResult.Success; if (this.PageLeaving != null) { this.PageLeaving(this, EventArgs.Empty); } } else { result = new WizardNavigationResult() { ErrorMessage = error, ShowMessageBoxOnFailure = true }; } } return result; }