Установить учетные данные Google из базы данных, в автономном режиме - PullRequest
0 голосов
/ 20 марта 2020

У меня большая проблема с отключением доступа к учетным данным Google. Я не хочу использовать файл для хранения учетных данных, потому что они будут храниться в базе данных для каждого пользователя отдельно. Как установить учетные данные Google из сохраненных значений - скажем, у меня есть refre sh токен в моей базе данных. Как установить этот рефрен sh токен из оффлайн?

    ClientSecrets secrets = new ClientSecrets();
          secrets.ClientId = "4-jq0b0m51ffsdfsdfwwerwr4214i.apps.googleusercontent.com";
          secrets.ClientSecret = "aRfssssseetiFSPZfffDs";

          string[] Scopes = { CalendarService.Scope.Calendar };

//Here is the problem - this method always forces user to get new token online
          UserCredential credential1 = GoogleWebAuthorizationBroker.AuthorizeAsync(
                secrets,
                      Scopes,
                      "user",
                      CancellationToken.None, new CustomDataStore()).Result;


public class CustomDataStore : IDataStore
{
//other methods omitted, they are not relevant for the question
    public Task<T> GetAsync<T>(string key)
    {
      //I guess this is the point where I would like to return refresh token from database
      throw new NotImplementedException();
    }

    public Task StoreAsync<TokenResponse>(string key, TokenResponse value)
    {
//I can save token at this point in the database, that's ok - but how to get token from DB?
      return Task.CompletedTask;
    }
}
...