I am converting Google token in json string format and storing that string in database.
Now while uploading files in google drive, I want to send that json in GoogleWebAuthorizationBroker.AuthorizeAsync method to get credentials which used to get DriveService.
So I can create a background task which checks the token and uploads files automatically without user interaction. Also I can use that credential to create new json file and save in Database so that if the access token is updated it can be store automatically.
UserCredential credential;
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "",
ClientSecret = ""
},
new[] { DriveService.Scope.Drive },
Page.User.Identity.Name,
CancellationToken.None).Result;
string json = JsonConvert.SerializeObject(credential.Token);
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Test",
});
Am I doing right thing ? Or is there any other way to save the credential in database rather then saving in file ?