GoogleWebAuthorizationBroker is not working from IIS Host

♀尐吖头ヾ 提交于 2019-11-28 14:45:54

(Reposting from https://github.com/google/google-api-dotnet-client/issues/888)

GoogleWebAuthorizationBroker is for use in an application that is running locally on an end-user machine. It opens a web browser locally allowing the user to authenticate. It sounds like you are trying to use GoogleWebAuthorizationBroker on a server machine, from within IIS; where it won't work, as it will try to open a web browser on that server machine - this will fail, and wouldn't be visible to the end-user anyway as it'll be on the server machine, not their machine.

I've not done this myself, but it looks like the instructions here (for an ASP.NET MVC web app) might help.

There are several different types of applications. You can have a web application, an native installed application or a mobile application. The methods used to authenticate these are slightly different.

The method GoogleWebAuthorizationBroker.AuthorizeAsync is used for native installed applications. It will open the browser window on the machine running the code. In the instance where you are running it in Visual studio it works fine but as soon as you try to host it it will try to open the browser window on the web server which wont work.

You need to be using GoogleAuthorizationCodeFlow which was designed for use with web applications. You can find an example here.

private static readonly IAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = new ClientSecrets
                {
                    ClientId = "PUT_CLIENT_ID_HERE",
                    ClientSecret = "PUT_CLIENT_SECRET_HERE"
                },
                Scopes = new[] { DriveService.Scope.Drive },
                DataStore = new FileDataStore("Drive.Api.Auth.Store")
            });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!