-
Notifications
You must be signed in to change notification settings - Fork 553
Expand file tree
/
Copy pathIGoogleCredential.cs
More file actions
129 lines (115 loc) · 6.29 KB
/
IGoogleCredential.cs
File metadata and controls
129 lines (115 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using Google.Apis.Http;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Google.Apis.Auth.OAuth2
{
/// <summary>
/// Represents a Google credential. Defines functionality that
/// credential types that can be used as an underlying credential in <see cref="GoogleCredential"/>
/// should implement in contrast to <see cref="ICredential"/> that defines public functionality.
/// </summary>
internal interface IGoogleCredential : ICredential, ITokenAccessWithHeaders, IHttpExecuteInterceptor
{
/// <summary>
/// The ID of the project associated to this credential for the purposes of
/// quota calculation and billing. May be null.
/// </summary>
string QuotaProject { get; }
/// <summary>
/// Returns a new instance of the same type as this but with the
/// given quota project value.
/// </summary>
/// <param name="quotaProject">The quota project value for the new instance.</param>
/// <returns>A new instance with the same type as this but with <see cref="QuotaProject"/>
/// set to <paramref name="quotaProject"/>.</returns>
IGoogleCredential WithQuotaProject(string quotaProject);
/// <summary>
/// Returns true if this credential scopes have been explicitly set via this library.
/// Returns false otherwise.
/// </summary>
bool HasExplicitScopes { get; }
/// <summary>
/// Returns true if this credential allows explicit scopes to be set
/// via this library.
/// Returns false otherwise.
/// </summary>
bool SupportsExplicitScopes { get; }
/// <summary>
/// Returns the universe domain this credential belongs to.
/// </summary>
/// <remarks>
/// For most credential types, this operation is synchronous and will always
/// return a completed task.
/// For <see cref="ComputeCredential"/>, the universe domain is obtained from the
/// metadata server, which requires an HTTP call. This value is obtained only once,
/// the first time it is requested for any instance of <see cref="ComputeCredential"/>.
/// Once the universe has been fetched this method will always return a completed task.
/// The task's result will never be null.
/// Note that each <paramref name="cancellationToken"/> will only apply to the call
/// that provided it and not to subsequent calls. For instance, even if the first call
/// to <see cref="GetUniverseDomainAsync(CancellationToken)"/> is cancelled, subsequent
/// calls may still succeed.
/// </remarks>
Task<string> GetUniverseDomainAsync(CancellationToken cancellationToken);
/// <summary>
/// Returns the universe domain this credential belongs to.
/// </summary>
/// <remarks>
/// Because <see cref="GetUniverseDomainAsync"/> is truly async only once, at most, in the lifetime
/// of an application, this method exists for convenience.
/// It can always be safely used for all credential types except for <see cref="ComputeCredential"/>.
/// For <see cref="ComputeCredential"/>, the universe domain is obtained from the
/// metadata server, which requires an HTTP call. This value is obtained only once,
/// the first time it is requested for any instance of <see cref="ComputeCredential"/>.
/// That first time, this method may block while waiting for the HTTP call to complete.
/// After that, this method will always be safe to use.
/// Will never return null.
/// </remarks>
string GetUniverseDomain();
/// <summary>
/// If the credential supports scopes, creates a copy with the specified scopes. Otherwise, it returns the same
/// instance.
/// </summary>
IGoogleCredential MaybeWithScopes(IEnumerable<string> scopes);
/// <summary>
/// If the credential supports domain wide delegation this method will create a copy of the
/// credential with the specified user set.
/// Otherwise, it throws <see cref="InvalidOperationException"/>.
/// </summary>
// TODO: Consider adding a IDomainWideDelegate interface. It's maybe of public interest to
// work only with credentials that support domain wide delegation. This interface would
// behave similar to IOIdcTokenProvider and IBlogSigner.
IGoogleCredential WithUserForDomainWideDelegation(string user);
/// <summary>
/// Return a new instance of the same type as this but that uses the
/// given HTTP client factory.
/// </summary>
/// <param name="httpClientFactory">The http client factory to be used by the new instance.
/// May be null in which case the default <see cref="HttpClientFactory"/> will be used.</param>
/// <returns>A new instance with the same type as this but that will use <paramref name="httpClientFactory"/>
/// to obtain an <see cref="ConfigurableHttpClient"/> to be used for token and other operations.</returns>
IGoogleCredential WithHttpClientFactory(IHttpClientFactory httpClientFactory);
/// <summary>
/// If the credential supports custom universe domains this method will create a copy of the
/// credential with the specified universe domain set.
/// Otherwise, it throws <see cref="InvalidOperationException"/>.
/// </summary>
/// <param name="universeDomain">The universe domain to use for the credential.
/// May be null, in which case the default universe domain will be used.</param>
IGoogleCredential WithUniverseDomain(string universeDomain);
}
}