- Version 1.0.2 Se introduce un reintento en la obtención de token
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Google.Apis.Auth.OAuth2;
|
||||
using Google.Apis.Util.Store;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -25,23 +26,33 @@ public static class GmailTokenManager
|
||||
public static async Task<string> ObtenerAccessTokenAsync(GmailConfig config)
|
||||
{
|
||||
var stream = new MemoryStream(config.ClientSecret);
|
||||
|
||||
await _tokenSemaphore.WaitAsync();
|
||||
try
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
var credencial = await GoogleWebAuthorizationBroker.AuthorizeAsync(
|
||||
GoogleClientSecrets.FromStream(stream).Secrets,
|
||||
new[] { "https://mail.google.com/" },
|
||||
config.Usuario,
|
||||
CancellationToken.None,
|
||||
new FileDataStore(config.TokenFolder, true)
|
||||
);
|
||||
i++;
|
||||
await _tokenSemaphore.WaitAsync();
|
||||
try
|
||||
{
|
||||
var credencial = await GoogleWebAuthorizationBroker.AuthorizeAsync(
|
||||
GoogleClientSecrets.FromStream(stream).Secrets,
|
||||
new[] { "https://mail.google.com/" },
|
||||
config.Usuario,
|
||||
CancellationToken.None,
|
||||
new FileDataStore(config.TokenFolder, true)
|
||||
);
|
||||
|
||||
return await credencial.GetAccessTokenForRequestAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_tokenSemaphore.Release();
|
||||
return await credencial.GetAccessTokenForRequestAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (i > 1) throw new Exception(ex.Message,ex);
|
||||
System.Threading.Thread.Sleep(5000);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_tokenSemaphore.Release();
|
||||
}
|
||||
}
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
<Company>Tecnosis S.A</Company>
|
||||
<Description>Envío de correos con cuentas de gmail</Description>
|
||||
<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.0 2025-09-18 Primera versión
|
||||
</PackageReleaseNotes>
|
||||
|
||||
Reference in New Issue
Block a user