Guest User

Untitled

a guest
Apr 25th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. public Google.Apis.Auth.OAuth2.UserCredential Autenticar()
  2. {
  3. string caminhoarquivo = @"c:ProComercio";
  4.  
  5. //Se o diretório não existir, ele irá criar esse novo diretório
  6. if (!Directory.Exists(caminhoarquivo))
  7. {
  8. //Criamos um com o nome folder
  9. Directory.CreateDirectory(caminhoarquivo);
  10. }
  11. string fileName = "client_id.json";
  12. string sourcePath = System.IO.Directory.GetCurrentDirectory();
  13. string targetPath = @"c:ProComercio";
  14. string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
  15. string destFile = System.IO.Path.Combine(targetPath, fileName);
  16. System.IO.File.Copy(sourceFile, destFile, true);
  17. using (var ctx = new Entities())
  18. {
  19. //Busca o email na tabela parametros
  20. var resultado = ctx.Clientes.SqlQuery("Select * from tblParametros").FirstOrDefault();
  21.  
  22. Google.Apis.Auth.OAuth2.UserCredential credenciais;
  23.  
  24. using (var stream = new System.IO.FileStream(caminhoarquivo + "client_id.json", System.IO.FileMode.Open, System.IO.FileAccess.Read))
  25. {
  26. var diretorioAtual = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  27. var diretorioCredenciais = System.IO.Path.Combine(diretorioAtual, "credential");
  28.  
  29. credenciais = Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(
  30. Google.Apis.Auth.OAuth2.GoogleClientSecrets.Load(stream).Secrets,
  31. new[] { Google.Apis.Drive.v3.DriveService.Scope.Drive },
  32. resultado.mailuser,
  33. System.Threading.CancellationToken.None,
  34. new Google.Apis.Util.Store.FileDataStore(diretorioCredenciais, true)).Result;
  35. }
  36. return credenciais;
  37. }
  38. }
Add Comment
Please, Sign In to add comment