简体   繁体   English

在 ASP.NET MVC 中添加新日历事件时,如何始终要求用户登录谷歌帐户?

[英]How to always request user to login google account when adding a new calendar event in ASP.NET MVC?

I have tried with GoogleWebAuthorizationBroker.AuthorizeAsync() but it is not working after I hosted in IIS. I have also try to use AppFlowMetadata but it is not open a new tab to ask for login.我尝试过使用GoogleWebAuthorizationBroker.AuthorizeAsync() ,但在我托管在 IIS 后它无法正常工作。我也尝试使用AppFlowMetadata ,但它没有打开新选项卡来要求登录。

GoogleWebAuthorizationBroker.AuthorizeAsync() is designed for installed applicaitons. GoogleWebAuthorizationBroker.AuthorizeAsync() 专为已安装的应用程序而设计。 The cosent screen is opened on the machine that the code is running on. cosent 屏幕在运行代码的机器上打开。 This will work fine when testing but when hosted on IIS its gong to try to open the browser window on your web server.这在测试时会正常工作,但当托管在 IIS 上时,它会尝试在您的 web 服务器上打开浏览器 window。

You need different code if you want to use it for a web application have a look at Web applications (ASP.NET Core 3) .如果要将它用于 web 应用程序,则需要不同的代码,请查看Web 应用程序 (ASP.NET Core 3)

[GoogleScopedAuthorize(CalendarService.ScopeConstants.Calendar)]
public async Task<IActionResult> CalendarEventsList([FromServices] IGoogleAuthProvider auth)
{
    GoogleCredential cred = await auth.GetCredentialAsync();
    var service = new CalendarService(new BaseClientService.Initializer
    {
        HttpClientInitializer = cred
    });
    var request = var request = service.Events.List("primary");       

    return View(request.Execute());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC中的Google Calendar API - Google Calendar API in ASP.NET MVC 当我在 asp.net core mvc 中未经授权时,如何始终返回登录/登录视图? - How to always return login/sign in view when I'm unauthorized in asp.net core mvc? 在 ASP.NET MVC 中登录成功时如何隐藏登录和注册事件? - How to hide Log In and Sign Up event when Login success in ASP.NET MVC? 如何使用ASP.NET MVC实现自动用户登录 - How to implement auto user login using asp.net mvc ASP.NET MVC3用户登录 - ASP.NET MVC3 User Login ASP.Net Core MVC登录用户 - ASP.Net Core MVC Login user 如何捕获由于授权Cookie过期而导致用户重定向到登录页面的瞬间ASP.NET MVC 3 - How to catch moment when user was redirected to login page because of authorization cookie expiration ASP.NET MVC 3 ASP.NET:如何判断账号登录? - ASP.NET: How to determine account login? 在我的新 PC 中使用 Visual Studio 运行 ASP.NET MVC 时,我向它发出的每个请求都会自动将其重定向到 Microsoft 登录 - When running my ASP.NET MVC with Visual Studio in my new PC, every request I make to it automatically redirects it to Microsoft login ASP.NET MVC调用新请求 - Asp.net MVC invoke new request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM