在.NET中Google预测API服务身份验证
-
11-12-2019 - |
题
我正在尝试建立一个可以访问谷歌预测API的.NET服务应用程序。
此应用程序是服务(无用户交互),所以我想知道如何自动对Google API进行身份验证(如果没有打开要登录的浏览器,然后按“授权”) 。
我尝试了什么:
-
运行的一些.NET Google API样本 - 它们似乎要求打开浏览器的此身份验证方案,并要求用户单击(这称为本机应用程序客户端认证,我相信)。
-
我很感兴趣,如果有人在之前有这种问题,那么决议是什么。如果在.NET中不可能(现在是),我还向非OAuth2(并且可能已弃用)身份验证解决方案开放。
解决方案
I've written a sample app (in Python & Java, sorry not available in C#) which authenticates once, stores the OAuth credentials and related data on the server (Google App Engine) and from that point forward reuses those shared credentials, refreshing the access token when needed, without requiring end users to see the OAuth allow/deny dialog, or any other aspect of OAuth.
This still requires the application administrator to execute the OAuth dialog but that's a one-time event. If for some reason you want to reset the stored server credentials, the initialization step can be re-executed on demand via a special URL, however, this reset function is protected so that only the application administrator can make that request, not an end user.