title: Google drive OAuth2 without browser
body: <p>I am trying to authenticate my login via <code>Google drive OAuth2</code> in my c# desktop app. And when the user enters <code>Client ID</code> and <code>Client secret</code>, the browser opens and asks for confirmation.
  Also browser opens when user enters a wrong <code>Client ID</code> and <code>Client secret</code> and shows an error message on the Google web page...</p>
  
  <p>So, haw can I authenticate without browser confirmation and handle all google OAuth2 errors inside my code and without any browser pages?</p>
  
  <p>Here is my authentication code:</p>
  
  <pre><code>//...code
  string[] scopes = new string[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile };
  
  UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
      new ClientSecrets
      {
          ClientId = "WrongID",
          ClientSecret = "WrongSecret"
      },
      scopes, _authUserName,
      CancellationToken.None, new FileDataStore(_authDataStorePath, true)).Result;
  //...code
  </code></pre>
  
  <p>And when error occurs in this block, execution of code just stops and nothing happens.</p>
  
  <p><strong>UPDATE1:</strong></p>
  
  <p>OK, suppose that I know how to get the json file with tokens.
  Now, how can I make DriveService object with this file?
  Now I create it as follows:</p>
  
  <pre><code>DriveService _drive = new DriveService(new BaseClientService.Initializer()
  {
      HttpClientInitializer = credential, // How to make this credential from tokens?
      ApplicationName = _applicationName
  });
  </code></pre>
  
  <p>Also, how about catching <code>Google OAuth exceptions</code> in my c# code? Couse now the Google just show me an error info in browser and my app just hangs...</p>