Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROTOTYPE: Auth separation #2405

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
183 changes: 0 additions & 183 deletions Src/Support/Google.Apis.Auth/ExistingDependencies/FileDataStore.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
using System.Threading.Tasks;

using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Util;
using Google.Apis.Util.Store;

namespace Google.Apis.Auth.OAuth2
Expand All @@ -34,22 +35,10 @@ namespace Google.Apis.Auth.OAuth2
/// </remarks>
public class GoogleWebAuthorizationBroker
{
// It's unforunate this is a public field. But it cannot be changed due to backward compatibility.
/// <summary>The folder which is used by the <see cref="Google.Apis.Util.Store.FileDataStore"/>.</summary>
/// <remarks>
/// The reason that this is not 'private const' is that a user can change it and store the credentials in a
/// different location.
/// </remarks>
public static string Folder = "Google.Apis.Auth";

/// <summary>
/// Asynchronously authorizes the specified user.
/// Requires user interaction; see <see cref="GoogleWebAuthorizationBroker"/> remarks for more details.
/// </summary>
/// <remarks>
/// In case no data store is specified, <see cref="Google.Apis.Util.Store.FileDataStore"/> will be used by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I'm not convinced it's a good idea to not provide a data store by default. I think FileDataStore might be a good candidate to move to that very light common library.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. I'd really hoped to get away without any concrete classes - and more importantly, FileDataStore uses NewtonsoftJsonSerializer.Instance :(

/// default.
/// </remarks>
/// <param name="clientSecrets">The client secrets.</param>
/// <param name="scopes">
/// The scopes which indicate the Google API access your application is requesting.
Expand All @@ -75,10 +64,6 @@ public static async Task<UserCredential> AuthorizeAsync(ClientSecrets clientSecr
/// Asynchronously authorizes the specified user.
/// Requires user interaction; see <see cref="GoogleWebAuthorizationBroker"/> remarks for more details.
/// </summary>
/// <remarks>
/// In case no data store is specified, <see cref="Google.Apis.Util.Store.FileDataStore"/> will be used by
/// default.
/// </remarks>
/// <param name="clientSecretsStream">
/// The client secrets stream. The authorization code flow constructor is responsible for disposing the stream.
/// </param>
Expand All @@ -87,12 +72,12 @@ public static async Task<UserCredential> AuthorizeAsync(ClientSecrets clientSecr
/// </param>
/// <param name="user">The user to authorize.</param>
/// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
/// <param name="dataStore">The data store, if not specified a file data store will be used.</param>
/// <param name="dataStore">The data store.</param>
/// <param name="codeReceiver">The code receiver, if not specified a local server code receiver will be used.</param>
/// <returns>User credential.</returns>
public static async Task<UserCredential> AuthorizeAsync(Stream clientSecretsStream,
IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken,
IDataStore dataStore = null, ICodeReceiver codeReceiver = null)
IDataStore dataStore, ICodeReceiver codeReceiver = null)
{
var initializer = new GoogleAuthorizationCodeFlow.Initializer
{
Expand Down Expand Up @@ -136,16 +121,15 @@ public static async Task ReauthorizeAsync(UserCredential userCredential,
/// </param>
/// <param name="user">The user to authorize.</param>
/// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
/// <param name="dataStore">The data store, if not specified a file data store will be used.</param>
/// <param name="dataStore">The data store. Must not be null.</param>
/// <param name="codeReceiver">The code receiver, if not specified a local server code receiver will be used.</param>
/// <returns>User credential.</returns>
public static async Task<UserCredential> AuthorizeAsync(
GoogleAuthorizationCodeFlow.Initializer initializer, IEnumerable<string> scopes, string user,
CancellationToken taskCancellationToken, IDataStore dataStore = null,
ICodeReceiver codeReceiver = null)
CancellationToken taskCancellationToken, IDataStore dataStore, ICodeReceiver codeReceiver = null)
{
initializer.Scopes = scopes;
initializer.DataStore = dataStore ?? new FileDataStore(Folder);
initializer.DataStore = dataStore.ThrowIfNull(nameof(dataStore));

var flow = new GoogleAuthorizationCodeFlow(initializer);
codeReceiver = codeReceiver ?? new LocalServerCodeReceiver();
Expand Down