title: C# WebApi 2 Google Drive authentication on server side
body: <p>I'm developing a web API that uses the google drive API, on my local machine, first run it redirected me to a google page to authenticate and then worked fine. Now I want to publish my code to Azure, and after I've published it the same function fails, because I could authenticate. How do I perform this authentication on the server?</p>
  
  <p>I've followed the .NET QuickStart (<a href="https://developers.google.com/drive/api/v3/quickstart/dotnet" rel="nofollow noreferrer">https://developers.google.com/drive/api/v3/quickstart/dotnet</a>), here is my code:</p>
  
  <pre><code>using (var stream =
              new FileStream($@"{dir}\client_secret.json", FileMode.Open, FileAccess.Read))
          {
              var cred = GoogleClientSecrets.Load(stream).Secrets;
              Credentials = GoogleWebAuthorizationBroker.AuthorizeAsync(
                  cred,
                  Scopes,
                  "user",
                  CancellationToken.None).Result;
          }
          service = new DriveService(new BaseClientService.Initializer()
          {
              HttpClientInitializer = Credentials,
              ApplicationName = ApplicationName,
          });
  }
  </code></pre>