Files
octokit.net/Octokit/Authentication/Authenticator.cs
Haacked 90f67dd37b Make credential store awaitable
The storage mechanism for credentials is very likely to be an async data
store. So might as well play it safe and make it awaitable.
2013-10-08 16:19:08 -07:00

34 lines
1.1 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit.Internal
{
class Authenticator
{
readonly Dictionary<AuthenticationType, IAuthenticationHandler> authenticators =
new Dictionary<AuthenticationType, IAuthenticationHandler>
{
{ AuthenticationType.Anonymous, new AnonymousAuthenticator() },
{ AuthenticationType.Basic, new BasicAuthenticator() },
{ AuthenticationType.Oauth, new AnonymousAuthenticator() }
};
public Authenticator(ICredentialStore credentialStore)
{
Ensure.ArgumentNotNull(credentialStore, "credentialStore");
CredentialStore = credentialStore;
}
public async Task Apply(IRequest request)
{
Ensure.ArgumentNotNull(request, "request");
var credentials = await CredentialStore.GetCredentials() ?? Credentials.Anonymous;
authenticators[credentials.AuthenticationType].Authenticate(request, credentials);
}
public ICredentialStore CredentialStore { get; set; }
}
}