Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Google.Apis.Auth.OAuth2.UserCredential Autenticar()
- {
- string caminhoarquivo = @"c:ProComercio";
- //Se o diretório não existir, ele irá criar esse novo diretório
- if (!Directory.Exists(caminhoarquivo))
- {
- //Criamos um com o nome folder
- Directory.CreateDirectory(caminhoarquivo);
- }
- string fileName = "client_id.json";
- string sourcePath = System.IO.Directory.GetCurrentDirectory();
- string targetPath = @"c:ProComercio";
- string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
- string destFile = System.IO.Path.Combine(targetPath, fileName);
- System.IO.File.Copy(sourceFile, destFile, true);
- using (var ctx = new Entities())
- {
- //Busca o email na tabela parametros
- var resultado = ctx.Clientes.SqlQuery("Select * from tblParametros").FirstOrDefault();
- Google.Apis.Auth.OAuth2.UserCredential credenciais;
- using (var stream = new System.IO.FileStream(caminhoarquivo + "client_id.json", System.IO.FileMode.Open, System.IO.FileAccess.Read))
- {
- var diretorioAtual = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- var diretorioCredenciais = System.IO.Path.Combine(diretorioAtual, "credential");
- credenciais = Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(
- Google.Apis.Auth.OAuth2.GoogleClientSecrets.Load(stream).Secrets,
- new[] { Google.Apis.Drive.v3.DriveService.Scope.Drive },
- resultado.mailuser,
- System.Threading.CancellationToken.None,
- new Google.Apis.Util.Store.FileDataStore(diretorioCredenciais, true)).Result;
- }
- return credenciais;
- }
- }
Add Comment
Please, Sign In to add comment