コード例 #1
0
        public async Task RefreshToken()
        {
            try
            {
                if (Account == null)
                {
                    return;
                }

                var ret = await BitbucketClient.GetRefreshToken(
                    Secrets.ClientId, Secrets.ClientSecret, Account.RefreshToken);

                if (ret == null)
                {
                    return;
                }

                Account.RefreshToken = ret.RefreshToken;
                Account.Token        = ret.AccessToken;
                _accountsService.Save(Account).ToBackground();

                Client = BitbucketClient.WithBearerAuthentication(Account.Token);
            }
            catch
            {
                // Do nothing....
            }
        }
コード例 #2
0
        protected async Task Startup()
        {
            var accounts = (await _accountsService.GetAccounts()).ToList();

            if (!accounts.Any())
            {
                GoToLoginCommand.ExecuteNow();
                return;
            }

            var account = await _applicationService.GetDefaultAccount();

            if (account == null)
            {
                GoToAccountsCommand.ExecuteNow();
                return;
            }

            if (string.IsNullOrEmpty(account.Token) || string.IsNullOrEmpty(account.RefreshToken))
            {
                GoToLoginCommand.ExecuteNow();
                return;
            }

            try
            {
                IsLoggingIn = true;
                Status      = "Logging in as " + account.Username;

                var ret = await BitbucketClient.GetRefreshToken(
                    Secrets.ClientId, Secrets.ClientSecret, account.RefreshToken);

                if (ret == null)
                {
                    await _alertDialogService.Alert("Error!", "Unable to refresh OAuth token. Please login again.");

                    GoToLoginCommand.ExecuteNow();
                    return;
                }

                account.RefreshToken = ret.RefreshToken;
                account.Token        = ret.AccessToken;
                await _accountsService.Save(account);
                await AttemptLogin(account);

                GoToMenuCommand.ExecuteNow();
            }
            catch (Exception e)
            {
                _alertDialogService
                .Alert("Error!", "Unable to login successfully: " + e.Message)
                .ToObservable()
                .BindCommand(GoToAccountsCommand);
            }
            finally
            {
                IsLoggingIn = false;
            }
        }