使用具有服务帐户的高级Google服务 [英] Using Advanced Google Services with Service Account

查看:78
本文介绍了使用具有服务帐户的高级Google服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Google App Script的应用程序,并使用一些高级服务,例如Admin SDK(Directory API)和Reseller API。

好像这些API是被我的WebApp在正在访问我的WebApp的用户的上下文中调用(它与'Execute the app as'User'访问webapp'一起部署)。

理想情况下,就像这些API的调用需要使用我的项目下的某个服务帐户进行验证(在Dev Console中)。它有可能吗?如何将脚本作为'用户访问Web应用程序'运行时,它会根据您的配额运行用户数据。

如果您想针对您的数据运行它,您需要更改设置以执行应用程序为我。



如果您需要执行混合身份验证模式,应用程序需要访问两个不同帐户的数据,你有一些选择。无论哪种方式,一个帐户访问内置的Apps脚本服务,另一个帐户将使用API​​的REST接口访问他们的数据。



您可以运行应用程序为我然后为用户管理你自己的Oauth。这可以通过OAuth Library完成,例如:

https://github.com/googlesamples/apps-script-oauth2



或者您可以以用户身份运行应用程序并使用服务考虑你的服务器。下面是一个我在爱尔兰应用脚本中使用服务帐户的图书馆:

https://github.com/Spencer-Easton/Apps-Script-GSApp-Library


I am developing an application using Google App Script and using some Advanced Services such as Admin SDK (Directory API) and Reseller API.

It seems like these API's are being called by my WebApp under context of user who is accessing my WebApp (it's deployed with 'Execute the app as 'User accessing the webapp').

Ideally, I would like these API's calls to be authenticated with some Service Account under my project (in Dev Console). It it possible? How?

解决方案

When your scripts are ran as 'User accessing the webapp' it runs off the users data against your quota. If you want to run it against your data you need to change the settings to execute the app as "me".

If you need to do a mixed authentication model where the app needs to access the data of two different accounts, you have some options. Either way one account gets to access the built in Apps Script services and the other will use the REST interfaces to the APIs to access their data.

You can run the app as "me" then manage your own Oauth for the user. This can be done with an OAuth Library such as:

https://github.com/googlesamples/apps-script-oauth2

Or you can run the app as the user and use a service account for your server. Here is a library I put together for using service accounts in Apps Script:

https://github.com/Spencer-Easton/Apps-Script-GSApp-Library

这篇关于使用具有服务帐户的高级Google服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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