- Version 1.0.2 Se introduce un reintento en la obtención de token

This commit is contained in:
2025-09-22 20:08:59 +02:00
parent 0473c38a34
commit 2b45864ba8
2 changed files with 27 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
using Google.Apis.Auth.OAuth2; using Google.Apis.Auth.OAuth2;
using Google.Apis.Util.Store; using Google.Apis.Util.Store;
using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -25,23 +26,33 @@ public static class GmailTokenManager
public static async Task<string> ObtenerAccessTokenAsync(GmailConfig config) public static async Task<string> ObtenerAccessTokenAsync(GmailConfig config)
{ {
var stream = new MemoryStream(config.ClientSecret); var stream = new MemoryStream(config.ClientSecret);
int i = 0;
await _tokenSemaphore.WaitAsync(); do
try
{ {
var credencial = await GoogleWebAuthorizationBroker.AuthorizeAsync( i++;
GoogleClientSecrets.FromStream(stream).Secrets, await _tokenSemaphore.WaitAsync();
new[] { "https://mail.google.com/" }, try
config.Usuario, {
CancellationToken.None, var credencial = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new FileDataStore(config.TokenFolder, true) GoogleClientSecrets.FromStream(stream).Secrets,
); new[] { "https://mail.google.com/" },
config.Usuario,
CancellationToken.None,
new FileDataStore(config.TokenFolder, true)
);
return await credencial.GetAccessTokenForRequestAsync(); return await credencial.GetAccessTokenForRequestAsync();
} }
finally catch (Exception ex)
{ {
_tokenSemaphore.Release(); if (i > 1) throw new Exception(ex.Message,ex);
System.Threading.Thread.Sleep(5000);
}
finally
{
_tokenSemaphore.Release();
}
} }
while (true);
} }
} }

View File

@@ -11,6 +11,7 @@
<Company>Tecnosis S.A</Company> <Company>Tecnosis S.A</Company>
<Description>Envío de correos con cuentas de gmail</Description> <Description>Envío de correos con cuentas de gmail</Description>
<PackageReleaseNotes> <PackageReleaseNotes>
- Version 1.0.2 Se introduce un reintento en la obtención de token
- Version 1.0.1 2025-09-22 Corrección rutinas asyncronas - Version 1.0.1 2025-09-22 Corrección rutinas asyncronas
- Version 1.0.0 2025-09-18 Primera versión - Version 1.0.0 2025-09-18 Primera versión
</PackageReleaseNotes> </PackageReleaseNotes>