Google Calendar Api在本地运行良好,但未在服务器上提高其身份验证 [英] Google Calendar Api working fine Locally but not raising its Authentication on Server

查看:83
本文介绍了Google Calendar Api在本地运行良好,但未在服务器上提高其身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在console.developers.google.com中创建了一个项目以使用Google Calendar API.那里我们需要生成凭证并选择应用程序类型

I have created a project in console.developers.google.com to use Google Calendar API. there we need to generate credential and select application type

对于Localhost和应用程序类型other,下面的Json可以正常工作.

For Localhost and application type other following is the Json which works fine.

{
    "installed": {
    "client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
    "project_id": "xxxxxx-00000",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://accounts.google.com/o/oauth2/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "xxxxxxxxxxxx",
    "redirect_uris": [ "urn:ietf:wg:oauth:2.0:oob", "http://localhost" ]
    }
}

对于在服务器上托管的应用程序类型Web ApplicationJson中的几个参数具有不同的值,如下所示.

And for Application type Web Application to Host on Server Few parameters has different Values in Json as shown below.

{
    "web": {
    "client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
    "project_id": "xxxxxxxx-99999",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://accounts.google.com/o/oauth2/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "xxxxxxxxxxxxxxxxxxxxxxx",
    "redirect_uris": [ "http://demo.mydemo.com" ],
    "javascript_origins": [ "http://demo.mydemo.com" ]
    }
}

在这种情况下,用户(只有那些集成了Google日历的用户)尝试创建活动时,Google应当同意使用哪个Google帐户并要求阅读个人数据,然后再重定向到重定向的页面. 征得同意后,它会将所提供的数据添加到所选的Google帐户的日历中.问题是它没有将用户重定向到Oauth身份验证,即The Consent Screen.

Here when user(Only those who have integrated Google Calendar) try to create an event Google should take consent of which google account to use and ask to read personal data before redirecting to the redirected page. On giving consent it will add the provided data in the selected google account's calendar. The Problem is It is not redirecting the user to Oauth Authentication i.e. The Consent Screen.

谁能帮我解决这个问题?

Can anyone help me to solve this issue?

错误如下

System.AggregateException: One or more errors occurred. ---> System.NotSupportedException: Failed to launch browser with "https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=xxxxxxxxxxxx-vqi4faduqgcpt3d2ruv53ltgr0rkgfsb.apps.googleusercontent.com&redirect_uri=http:%2F%2Flocalhost:53998%2Fauthorize%2F&scope=https:%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar" for authorization. See inner exception for details. ---> System.ComponentModel.Win32Exception: Access is denied
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.<ReceiveCodeAsync>d__8.MoveNext()
   --- End of inner exception stack trace ---
   at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.<ReceiveCodeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.<AuthorizeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__1.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at KriyaCRM.Controllers.ActivitiesController.GetCalendarConnection(Activities objact, String Operation)
---> (Inner Exception #0) System.NotSupportedException: Failed to launch browser with "https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=430760523223-vqi4faduqgcpt3d2ruv53ltgr0rkgfsb.apps.googleusercontent.com&redirect_uri=http:%2F%2Flocalhost:53998%2Fauthorize%2F&scope=https:%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar" for authorization. See inner exception for details. ---> System.ComponentModel.Win32Exception: Access is denied
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.<ReceiveCodeAsync>d__8.MoveNext()
   --- End of inner exception stack trace ---
   at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.<ReceiveCodeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.<AuthorizeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__1.MoveNext()<---
--> Important Link related to API : https://www.codeproject.com/Articles/1183150/Securing-ASP-NET-Web-API-using-Custom-Token-Based <--

推荐答案

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
                                                                             scopes,
                                                                             userName,
                                                                             CancellationToken.None,
                                                                             new FileDataStore(credPath, true)).Result;

用于已安装的应用程序.当您在调试模式下运行代码时,它可能会起作用,因为您可以打开本地计算机上的Web浏览器.但是,当您尝试将其托管在服务器上时,由于您无权在服务器上打开Web浏览器,因此无法正常工作,而您想做的就是在客户端计算机上打开Web浏览器.

Is used for installed applications. It will probably work when you are running your code in debug mode because you have access to open a web browser on your local-machine. However when you try to host it on a server its not going to work because you don't have access to open a web browser on the server what you want to do is open a web browser on the clients machine.

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")
                });

您应该尝试关注本文. Google Oauth2 asp.net MVC

You should try following this article. Google Oauth2 asp.net MVC

这篇关于Google Calendar Api在本地运行良好,但未在服务器上提高其身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆