| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | using Google.Apis.Http; |
| | using System; |
| | using System.Collections.Generic; |
| | using System.Net.Http; |
| | using System.Threading; |
| | using System.Threading.Tasks; |
| |
|
| | namespace Google.Apis.Auth.OAuth2 |
| | { |
| | |
| | |
| | |
| | |
| | |
| | internal class AccessTokenCredential : IGoogleCredential, IHttpExecuteInterceptor |
| | { |
| | private readonly string _accessToken; |
| | private readonly IAccessMethod _accessMethod; |
| | private readonly string _universeDomain; |
| |
|
| | |
| | public string QuotaProject { get; } |
| |
|
| | |
| | bool IGoogleCredential.HasExplicitScopes => false; |
| |
|
| | |
| | bool IGoogleCredential.SupportsExplicitScopes => false; |
| |
|
| | public AccessTokenCredential( |
| | string accessToken, IAccessMethod accessMethod, string quotaProject = null, string universeDomain = null) |
| | { |
| | _accessToken = accessToken; |
| | _accessMethod = accessMethod; |
| | QuotaProject = quotaProject; |
| | _universeDomain = universeDomain ?? GoogleAuthConsts.DefaultUniverseDomain; |
| | } |
| |
|
| | |
| | public GoogleCredential ToGoogleCredential() => new GoogleCredential(this); |
| |
|
| | |
| | Task<string> IGoogleCredential.GetUniverseDomainAsync(CancellationToken _) => Task.FromResult(_universeDomain); |
| |
|
| | |
| | string IGoogleCredential.GetUniverseDomain() => _universeDomain; |
| |
|
| | |
| | IGoogleCredential IGoogleCredential.WithQuotaProject(string quotaProject) => |
| | new AccessTokenCredential(_accessToken, _accessMethod, quotaProject, _universeDomain); |
| |
|
| | |
| | IGoogleCredential IGoogleCredential.MaybeWithScopes(IEnumerable<string> scopes) => this; |
| |
|
| | |
| | IGoogleCredential IGoogleCredential.WithUserForDomainWideDelegation(string user) => |
| | throw new InvalidOperationException($"{nameof(AccessTokenCredential)} does not support Domain-Wide Delegation"); |
| |
|
| | |
| | IGoogleCredential IGoogleCredential.WithHttpClientFactory(IHttpClientFactory httpClientFactory) => this; |
| |
|
| | |
| | IGoogleCredential IGoogleCredential.WithUniverseDomain(string universeDomain) => |
| | new AccessTokenCredential(_accessToken, _accessMethod, QuotaProject, universeDomain); |
| |
|
| | public void Initialize(ConfigurableHttpClient httpClient) => |
| | httpClient.MessageHandler.Credential = this; |
| |
|
| | public Task<string> GetAccessTokenForRequestAsync(string authUri = null, CancellationToken cancellationToken = default(CancellationToken)) => |
| | Task.FromResult(_accessToken); |
| |
|
| | |
| | public Task<AccessTokenWithHeaders> GetAccessTokenWithHeadersForRequestAsync(string authUri = null, CancellationToken cancellationToken = default) => |
| | Task.FromResult(new AccessTokenWithHeaders.Builder { QuotaProject = QuotaProject }.Build(_accessToken)); |
| |
|
| | |
| | public Task InterceptAsync(HttpRequestMessage request, CancellationToken taskCancellationToken) |
| | { |
| | var accessToken = new AccessTokenWithHeaders.Builder { QuotaProject = QuotaProject }.Build(_accessToken); |
| | _accessMethod.Intercept(request, accessToken.AccessToken); |
| | accessToken.AddHeaders(request); |
| |
|
| | return Task.FromResult(true); |
| | } |
| | } |
| | } |
| |
|