Agregar archivos de proyecto.
This commit is contained in:
31
GmailTokenManager.cs
Normal file
31
GmailTokenManager.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Google.Apis.Auth.OAuth2;
|
||||
using Google.Apis.Util.Store;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public static class GmailTokenManager
|
||||
{
|
||||
public static async Task<string> ObtenerAccessTokenAsync(GmailConfig config)
|
||||
{
|
||||
//var stream = new FileStream(config.ClientSecretPath, FileMode.Open, FileAccess.Read);
|
||||
var stream = new MemoryStream(config.ClientSecret);
|
||||
|
||||
//var credencial = await GoogleWebAuthorizationBroker.AuthorizeAsync(
|
||||
// GoogleClientSecrets.FromStream(stream).Secrets,
|
||||
// new[] { "https://www.googleapis.com/auth/gmail.send" },
|
||||
// config.Usuario,
|
||||
// CancellationToken.None,
|
||||
// new FileDataStore(config.TokenFolder, true)
|
||||
//);
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user