通过Windows Service访问Google API [英] Google API access from Windows Service

查看:52
本文介绍了通过Windows Service访问Google API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC Web应用程序中实现了Google Apps API,以访问Admin SDK来从Google Apps帐户添加/删除用户.在我的网络应用中,首先用户需要通过Google Apps帐户(OAuth 2.0)进行身份验证,然后将accesstoken和refreshtoken存储在数据库存储中.之后,Admin SDK API在Web应用程序中用于添加/删除用户功能的调用使用脱机"模式,因为它不会弹出同意屏幕.

I implemented Google apps API in a MVC Web app, to access for Admin SDK to add/remove users from Google apps account. In my web app, first the user needs to authenticate with the Google Apps account (OAuth 2.0), then I store the accesstoken and refreshtoken in the database storage. After that,Admin SDK API calls to add/remove user functionality in the web app uses the "offline" mode as it does not pop up the consent screen.

但是我需要使用我的数据库令牌存储(accesstokens/refreshtokens)进行身份验证.我怎样才能做到这一点?

But I need to use my database token storage(accesstokens/refreshtokens) for the authentication. How can I do this?

我的要求类似于此问题.但是问题在于内容已被修改,这些示例的URL不再存在.

My requirement is similar to this question. But the issue is that the content is modified and URLs to those samples are no longer there.

推荐答案

我无法以一种很好的方式完成此任务,我不得不做一些改动.(实际上,只要访问令牌是活动的,就可以做到,问题是当我们需要刷新令牌时).

I could not accomplish this task in a nice way, I had to do few hacks. (In fact as long as the access token is live this can be done, problem occurs is when we need to refresh the token).

最后,我实现了一个可以处理令牌刷新的WebAPI项目,其工作原理与MVC应用程序非常相似.Windows服务在需要API调用时与Web API项目进行通信,并在完成工作后获得响应.

Finally I implemented a WebAPI project which can handle token refreshing, works pretty much similar to the MVC app. Windows service communicates with the web API project when it requires the API call and get the response after the job done.

这篇关于通过Windows Service访问Google API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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