mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 06:05:12 +00:00
34 lines
1.1 KiB
C#
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().ConfigureAwait(false) ?? Credentials.Anonymous;
|
|
authenticators[credentials.AuthenticationType].Authenticate(request, credentials);
|
|
}
|
|
|
|
public ICredentialStore CredentialStore { get; set; }
|
|
}
|
|
}
|