如何使用服务配置Meteor包重新定义OAuth范围



我在Meteor应用程序中添加了service-configuration包,并试图重新定义谷歌的授权范围,特别是让应用程序请求访问日历。默认设置为

ServiceConfiguration.configurations.update({}, {
  service: 'google',
  clientId: CLIENT_ID,
  secret: CLIENT_SECRET,
  loginStyle: 'redirect'
}, {
  upsert: true
});

所以我想做的是给options对象添加额外的属性:

ServiceConfiguration.configurations.update({}, {
  service: 'google',
  clientId: CLIENT_ID,
  secret: CLIENT_SECRET,
  loginStyle: 'redirect',
  requestPermissions: [
    'https://www.googleapis.com/auth/calendar',
    'https://www.googleapis.com/auth/calendar.readonly'
  ]
}, {
  upsert: true
});

它不起作用。文档稀疏。有人能告诉我一个方向吗?这样我就可以通过Meteor应用程序中的谷歌API访问用户的日历数据了?

我不使用谷歌的官方Node包,也不打算这样做。我相信有一种更简单的方法可以通过应用程序中的透明HTTP请求访问他们的API。

看看涉及的两个软件包(google和accounts google),你似乎把选项放错了地方。它们不是从数据库中的服务配置中读取的,而是直接从loginWithGoogle函数调用的第一个参数中读取的。

也就是说,以下内容应该有效(数据库中的服务配置没有更改):

Meteor.loginWithGoogle({
    loginStyle: 'redirect',
    requestPermissions: [
        'https://www.googleapis.com/auth/calendar',
        'https://www.googleapis.com/auth/calendar.readonly'
    ]
}, function() { console.log("login successful); });

更新:

如果您使用的是loginButtons模板,那么它会更容易,如文档中所述:

Accounts.ui.config({
  requestPermissions: {
    google: [
        'https://www.googleapis.com/auth/calendar',
        'https://www.googleapis.com/auth/calendar.readonly'
    ]
  }
});

最新更新