/// <summary>Asynchronously authorizes the specified user.</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>
 /// <param name="scopes">
 /// The scopes which indicate the Google API access your application is requesting.
 /// </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="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)
 {
     var initializer = new GoogleAuthorizationCodeFlow.Initializer
     {
         ClientSecretsStream = clientSecretsStream,
     };
     return await AuthorizeAsync(initializer, scopes, user, taskCancellationToken, dataStore, codeReceiver)
         .ConfigureAwait(false);
 }
Beispiel #2
0
 public googleauth(GoogleAuthorizationCodeFlow flow, ICodeReceiver codeReceiver)
 { 
     this.flow = flow;
     this.codeReceiver = codeReceiver;
 }
 /// <summary>
 /// Constructs a new authorization code installed application with the given flow and code receiver.
 /// </summary>
 public AuthorizationCodeInstalledApp(IAuthorizationCodeFlow flow, ICodeReceiver codeReceiver)
 {
     this.flow = flow;
     this.codeReceiver = codeReceiver;
 }
 /// <summary>
 /// Asynchronously reauthorizes the user. This method should be called if the users want to authorize after 
 /// they revoked the token.
 /// </summary>
 /// <param name="userCredential">The current user credential. Its <see cref="UserCredential.Token"/> will be
 /// updated. </param>
 /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
 /// <param name="codeReceiver">The code receiver, if not specified a local server code receiver will be used.</param>
 public static async Task ReauthorizeAsync(UserCredential userCredential,
     CancellationToken taskCancellationToken, ICodeReceiver codeReceiver = null)
 {
     codeReceiver = codeReceiver ?? new LocalServerCodeReceiver();
     
     // Create an authorization code installed app instance and authorize the user.
     UserCredential newUserCredential = await new AuthorizationCodeInstalledApp(userCredential.Flow,
         codeReceiver).AuthorizeAsync
         (userCredential.UserId, taskCancellationToken).ConfigureAwait(false);
     userCredential.Token = newUserCredential.Token;
 }
        /// <summary>The core logic for asynchronously authorizing the specified user.</summary>
        /// <param name="initializer">The authorization code initializer.</param>
        /// <param name="scopes">
        /// The scopes which indicate the Google API access your application is requesting.
        /// </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="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)
        {
            initializer.Scopes = scopes;
            initializer.DataStore = dataStore ?? new FileDataStore(Folder);

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

            // Create an authorization code installed app instance and authorize the user.
            return await new AuthorizationCodeInstalledApp(flow, codeReceiver).AuthorizeAsync
                (user, taskCancellationToken).ConfigureAwait(false);
        }
 /// <summary>
 /// Constructs a new authorization code installed application with the given flow and code receiver.
 /// </summary>
 public AuthorizationCodeInstalledApp(IAuthorizationCodeFlow flow, ICodeReceiver codeReceiver)
 {
     this.flow         = flow;
     this.codeReceiver = codeReceiver;
 }
Beispiel #7
0
        public new static async Task <UserCredential> AuthorizeAsync(ClientSecrets clientSecrets,
                                                                     IEnumerable <string> scopes, string user, CancellationToken taskCancellationToken,
                                                                     IDataStore dataStore = null, ICodeReceiver codeReceiver = null)
        {
            var initializer = new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = clientSecrets,
            };

            return(await AuthorizeAsyncCore(initializer, scopes, user, taskCancellationToken, dataStore)
                   .ConfigureAwait(false));
        }
        /// <summary>
        /// Asynchronously reauthorizes the user. This method should be called if the users want to authorize after
        /// they revoked the token.
        /// Requires user interaction; see <see cref="GoogleWebAuthorizationBroker"/> remarks for more details.
        /// </summary>
        /// <param name="userCredential">The current user credential. Its <see cref="UserCredential.Token"/> will be
        /// updated. </param>
        /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
        /// <param name="codeReceiver">The code receiver, if not specified a local server code receiver will be used.</param>
        public static async Task ReauthorizeAsync(UserCredential userCredential,
                                                  CancellationToken taskCancellationToken, ICodeReceiver codeReceiver = null)
        {
            codeReceiver = codeReceiver ?? new LocalServerCodeReceiver();

            // Delete token, which forces a user-interactive re-auth to occur.
            await userCredential.Flow.DeleteTokenAsync(userCredential.UserId, taskCancellationToken).ConfigureAwait(false);

            // Create an authorization code installed app instance and authorize the user.
            UserCredential newUserCredential = await new AuthorizationCodeInstalledApp(userCredential.Flow,
                                                                                       codeReceiver).AuthorizeAsync
                                                   (userCredential.UserId, taskCancellationToken).ConfigureAwait(false);

            userCredential.Token = newUserCredential.Token;
        }