Esempio n. 1
0
        /// <summary>
        /// This time you do have a refreshToken for the user stored in tbrefreshToken.  We will use that to request there data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLoadSavedData_Click(object sender, EventArgs e)
        {
            UserCredential StoredCredential;

            tbFileCount.Text = "0";

            //Now we load our saved refreshToken.
            StoredResponse myStoredResponse = new StoredResponse(tbRefreshToken.Text);

            // Now we pass a SavedDatastore with our StoredResponse.
            using (var stream = new FileStream("client_secrets.json", FileMode.Open,
                                               FileAccess.Read))
            {
                GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store";
                StoredCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { DriveService.Scope.Drive,
                            DriveService.Scope.DriveFile },
                    "user",
                    CancellationToken.None,
                    new SavedDataStore(myStoredResponse)).Result;
            }

            // If you check StoredCredentail right now the values are what we passed to it.
            tbAccessToken.Text  = StoredCredential.Token.AccessToken;
            tbRefreshToken.Text = StoredCredential.Token.RefreshToken;
            tbTokenType.Text    = StoredCredential.Token.TokenType;
            tbExpiresIn.Text    = StoredCredential.Token.ExpiresInSeconds.ToString();
            tbIssued.Text       = StoredCredential.Token.Issued.ToString();

            // This is how we connect to google drive.  Only puting this here so that you can see it is able to access
            // the google drive api.
            DriveService service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = StoredCredential,
                ApplicationName       = "Drive API Sample",
            });

            FilesResource.ListRequest request = service.Files.List();
            FileList files = request.Execute();

            tbFileCount.Text = files.Items.Count().ToString();

            // after you have made a request StoredCredentail will be filled out it will get a new access token
            // for you based upon the refreshtoken you sent
            // You dont need to resave any of this.  The refresh token you already have is enough.
            tbAccessToken.Text  = StoredCredential.Token.AccessToken;
            tbRefreshToken.Text = StoredCredential.Token.RefreshToken;
            tbTokenType.Text    = StoredCredential.Token.TokenType;
            tbExpiresIn.Text    = StoredCredential.Token.ExpiresInSeconds.ToString();
            tbIssued.Text       = StoredCredential.Token.Issued.ToString();
        }
Esempio n. 2
0
 public SavedDataStore()
 {
     this._storedResponse = new StoredResponse();
 }
Esempio n. 3
0
 /// <summary>
 /// Clears all values in the data store.
 /// </summary>
 public Task ClearAsync()
 {
     this._storedResponse = new StoredResponse();
     return(TaskEx.Delay(0));
 }
Esempio n. 4
0
        /// <summary>
        /// Constructs Load perviously saved StoredResponse.
        /// </summary>
        /// <param name="StoredResponse">Stored response</param>

        public SavedDataStore(StoredResponse pResponse)
        {
            this._storedResponse = pResponse;
        }
Esempio n. 5
0
        /// <summary>
        /// Deletes StoredResponse.
        /// </summary>
        /// <param name="key">The key to delete from the data store</param>
        public Task DeleteAsync <T>(string key)
        {
            this._storedResponse = new StoredResponse();

            return(TaskEx.Delay(0));
        }