0

I'm working with Google Drive API v3 in ASP.NET Core WebApi project but it's not working on IIS. It works fine locally via Visual Studio 2017 on Kestrel server. However if I try to deploy on IIS it hangs.

Code snippet for listing image files located in a folder:

public static Google.Apis.Drive.v3.Data.FileList ListFiles(DriveService service, string folderId)
{
    try
    {
        var request = service.Files.List();
        request.PageSize = 100;
        request.Fields = "nextPageToken, files(id, name)";
        if (!String.IsNullOrEmpty(folderId))
        {
            request.Q = "'" + folderId + "' in parents " + " and mimeType='image/jpeg'";
        }
        return request.Execute();
    }
    catch (Exception ex)
    {
        throw new Exception("Request failed.", ex);
    }
}

I know well Google Drive API supports OAuth 2.0 for web spplications (ASP.NET MVC) as described here: https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#web-applications-aspnet-mvc

Please help. Thanks.

murtaza erti
  • 37
  • 1
  • 4
  • Please provide the exact error details you are getting either on the browser or on the console. – Ipsit Gaur Apr 19 '18 at 04:16
  • Please include your authentication code. Where is the IIS server? are we talking Azure? – Linda Lawton - DaImTo Apr 19 '18 at 05:51
  • 1
    I think this has something to do with IIS configuration. Try checking the [Web applications (ASP.NET MVC)](https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#web-applications-aspnet-mvc) implementation for .NET. It says you need to "set the redirect URI to your_site/AuthCallback/IndexAsync" and more. Also, some pointers from this [github forum](https://github.com/google/google-api-dotnet-client/issues/888#issuecomment-290421752) might help. – ReyAnthonyRenacia Apr 19 '18 at 11:00
  • I think most of the sample codes provided by Google for work with installed applications. Its not going to work for web applications. – murtaza erti Apr 23 '18 at 17:42

1 Answers1

0

This looks like the issue I am facing. The problem is that the code for authorization you are using is probably from a code snipped made for desktop applications. That's why it works on you local machine, but once you deploy it everything changes. If you try to authorize using this code from a server-run application, it will try to open the authorization windows ON THAT SERVER MACHINE and hang.

One workaround would be to change application type in Google API console to "Other", but that's a bit risky since your user will use Server specified identity to authorize with google and you'll have to build another layer of security to filter requests.

As of now (August 6 2018) Google does not support .net Core for web server authorization as far as I can see. You can track the progress on Github here.

If you are willing to switch to classic ASP MVC, you can use this code snipped with no problem.

Also, here is a similar thread if it helps you somehow.