using System.Collections.Generic; using System.Threading.Tasks; namespace Octokit.Internal { class Authenticator { readonly Dictionary authenticators = new Dictionary { { 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; } } }