【问题标题】:How to impersonate a user and insert a calendar in its behalf using service account?如何使用服务帐户模拟用户并代表其插入日历?
【发布时间】:2019-02-03 22:51:18
【问题描述】:

我正在尝试创建日历并使用服务帐户与我单位的用户共享它们。
我想要获得的是能够从我的网站代码(使用服务帐户)和常规的谷歌日历网络界面管理创建的日历。
所以我想我可以创建一个愚蠢的用户帐户(带有凭据),用服务帐户模拟它,然后从我的 weba 应用程序代码和谷歌常规用户界面创建和共享我的日历并管理事件。
这是正确的方法吗?我错过了什么吗?
如果我最后的猜测是正确的,我如何使用 laravel 和 google-api-clients for PHP 来实现它?

感谢您的建议

【问题讨论】:

  • 组织的用户我们在说 gsuite 吗?
  • 你检查过这个SO post吗?
  • @daimto 是的,我们正在谈论 gsuite 组织

标签: laravel-5 google-calendar-api google-api-php-client service-accounts


【解决方案1】:

在上面睡觉后,我意识到没有必要冒充用户并插入新日历。 要从官方 Web 界面管理服务帐户日历,您只需将其与所有者权限共享给“哑用户”

这样的:

//create calendar
$calendar = new Google_Service_Calendar_Calendar();
$calendar->setSummary('calendarname');
$calendar->setTimeZone('Europe/Berlin');
$service = new Google_Service_Calendar();
$createdCalendar = $service->calendars->insert($calendar);

//share it with your dumb user 
$rule = new Google_Service_Calendar_AclRule();
$scope = new Google_Service_Calendar_AclRuleScope();
$scope->setType("user");
$scope->setValue('dumbuser@organization.com');
$rule->setScope($scope);
$rule->setRole("owner");
$createdRule = $service->acl->insert(createdCalendar->getId(), $rule);

所以我的问题暂时解决了,我仍在考虑的唯一问题是如何模拟具有服务帐户凭据的用户?好用的时候再考虑考虑

【讨论】:

    猜你喜欢
    • 2014-11-21
    • 2018-02-10
    • 1970-01-01
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    相关资源
    最近更新 更多