示例#1
0
        async Task <ApplicationAuthorization> HandleTwoFactorAuthorization(
            HostAddress hostAddress,
            IGitHubClient client,
            NewAuthorization newAuth,
            TwoFactorAuthorizationException exception)
        {
            for (;;)
            {
                var challengeResult = await twoFactorChallengeHandler.HandleTwoFactorException(exception);

                if (challengeResult == null)
                {
                    throw new InvalidOperationException(
                              "ITwoFactorChallengeHandler.HandleTwoFactorException returned null.");
                }

                if (!challengeResult.ResendCodeRequested)
                {
                    try
                    {
                        var auth = await CreateAndDeleteExistingApplicationAuthorization(
                            client,
                            newAuth,
                            challengeResult.AuthenticationCode).ConfigureAwait(false);

                        return(EnsureNonNullAuthorization(auth));
                    }
                    catch (TwoFactorAuthorizationException e)
                    {
                        exception = e;
                    }
                    catch (Exception e)
                    {
                        await twoFactorChallengeHandler.ChallengeFailed(e);

                        await loginCache.EraseLogin(hostAddress).ConfigureAwait(false);

                        throw;
                    }
                }
                else
                {
                    return(null);
                }
            }
        }