Implement GetOrCreateApplicationAuthentication

Implements the endpoint for creating an application authorization token.
This commit is contained in:
Haacked
2013-10-09 16:28:59 -07:00
parent 9d71d406fa
commit 33ad79c0fe
19 changed files with 653 additions and 4 deletions
@@ -0,0 +1,41 @@
using System;
using System.Threading.Tasks;
namespace Octokit
{
public static class AuthorizationExtensions
{
public static async Task<Authorization> GetOrCreateApplicationAuthentication(
this IAuthorizationsClient authorizationsClient,
string clientId,
string clientSecret,
AuthorizationUpdate authorization,
Func<TwoFactorRequiredException, Task<TwoFactorChallengeResult>> twoFactorChallengeHandler
)
{
TwoFactorRequiredException twoFactorException = null;
try
{
return await authorizationsClient.GetOrCreateApplicationAuthentication(clientId, clientSecret, authorization);
}
catch (TwoFactorRequiredException exception)
{
twoFactorException = exception;
}
var twoFactorChallengeResult = await twoFactorChallengeHandler(twoFactorException);
return await (twoFactorChallengeResult.ResendCodeRequested
? authorizationsClient.GetOrCreateApplicationAuthentication(
clientId,
clientSecret,
authorization,
twoFactorChallengeHandler)
: authorizationsClient.GetOrCreateApplicationAuthentication(clientId,
clientSecret,
authorization,
twoFactorChallengeResult.AuthenticationCode));
}
}
}