public override async Task SignIn(CancellationToken cancellation) {
await Prepare(cancellation);
if (IsReady && DateTime.Now < _authExpiration) return;
var data = InternalUtils.GetGoogleDriveCredentials();
var clientId = data.Item1.Substring(2);
var clientSecret = data.Item2.Substring(2);
var code = await GetAutenficationCode(clientId, cancellation);
if (cancellation.IsCancellationRequested) return;
if (code == null) {
throw new UserCancelledException();
}
var response = await Request.Post<AuthResponse>(@"https://www.googleapis.com/oauth2/v4/token", new NameValueCollection {
{ @"code", code },
{ @"client_id", clientId },
{ @"client_secret", clientSecret },
{ @"redirect_uri", RedirectUrl },
{ @"grant_type", @"authorization_code" }
}.GetQuery(), null, cancellation);
if (cancellation.IsCancellationRequested) return;
if (response == null) {
throw new Exception(ToolsStrings.Uploader_CannotFinishAuthorization);
}
_authToken = response;
_authExpiration = DateTime.Now + TimeSpan.FromSeconds(response.ExpiresIn) - TimeSpan.FromSeconds(20);
ValuesStorage.SetEncrypted(KeyAuthToken, JsonConvert.SerializeObject(_authToken));
ValuesStorage.Set(KeyAuthExpiration, _authExpiration);
IsReady = true;
}