コード例 #1
0
        /// <summary>
        /// Authenticates a client using browser consent form, may require login and password for Google account.
        /// </summary>
        /// <param name="cancellationToken">Token that allows to cancel authentication task.</param>
        /// <param name="secrets">A set of client secrets to use when authenticating.</param>
        /// <param name="scopes">A set of capabilities to request from Google services.</param>
        /// <param name="log">Logger that accepts debug info.</param>
        /// <param name="dataStoreName">Name of a file data store to use to store credentials.</param>
        /// <returns>Refresh token.</returns>
        /// <exception cref="OperationCanceledException">Operation was cancelled by user.</exception>
        public static async Task <string> AuthenticateManually(
            CancellationToken cancellationToken,
            ClientSecrets secrets,
            IEnumerable <string> scopes,
            IIoLogger log,
            string dataStoreName)
        {
            try
            {
                var dataStore  = new DummyDataStore();
                var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                    secrets,
                    scopes,
                    "user",
                    cancellationToken,
                    dataStore);

                log.LogMessage("Successfully authenticated");
                return(credential.Token.RefreshToken);
            }
            catch (Exception e)
            {
                if (e is OperationCanceledException)
                {
                    throw (OperationCanceledException)e;
                }

                log.LogError("Authentication error", e);
                throw;
            }
        }
コード例 #2
0
 /// <inheritdoc />
 protected override void UpdateLog(IIoLogger logger)
 {
     lock (this)
     {
         foreach (var task in this.childTasks)
         {
             task.Log = logger;
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Authenticates a client using browser consent form, may require login and password for Google account.
        /// </summary>
        /// <param name="cancellationToken">Token that allows to cancel authentication task.</param>
        /// <param name="log">Logger object used to output debug info.</param>
        /// <returns>Refresh token.</returns>
        /// <exception cref="OperationCanceledException">Operation was cancelled by user.</exception>
        public static async Task <string> AuthenticateManually(CancellationToken cancellationToken, IIoLogger log)
        {
            log.LogMessage("Authorizing manually for Google Drive as Google Drive Sync");
            string[] scopes  = { DriveService.Scope.DriveReadonly };
            var      secrets = new ClientSecrets
            {
                ClientId     = Constants.GoogleDriveSyncClientId,
                ClientSecret = Constants.GoogleDriveSyncClientSecret
            };

            return(await ManualAuthenticator.AuthenticateManually(
                       cancellationToken,
                       secrets,
                       scopes,
                       log,
                       "GoogleDrive_Datastore"));
        }
コード例 #4
0
 public TaskContext(IIoLogger log, CancellationToken cancellationToken, TaskStatusAccumulator statusAccumulator)
 {
     this.Log = log;
     this.CancellationToken = cancellationToken;
     this.statusAccumulator = statusAccumulator;
 }
コード例 #5
0
 /// <summary>
 /// Virtual method that is called when Log property changes and shall be overriden to propagate log changing.
 /// </summary>
 /// <param name="logger">New logger object.</param>
 protected virtual void UpdateLog(IIoLogger logger)
 {
 }