【发布时间】:2021-10-26 17:03:37
【问题描述】:
我正在尝试让 Google 验证我的应用是否适用于两个 Google 联系人只读范围,以便用户可以将他们的联系人导入我的应用。
https://www.googleapis.com/auth/contacts.readonly
https://www.googleapis.com/auth/contacts.other.readonly
我正在使用 Auth0 在我的 Next.js 应用程序中处理用户。我使用的包是@auth0/nextjs-auth0。我已经按照文档的建议初始化了 auth0。
// pages/api/auth/[...auth0].ts
import {handleAuth} from '@auth0/nextjs-auth0';
export default handleAuth();
在 Auth0 的 Google 社交连接中,我选中了 Contacts 框,当我使用 Google 登录时,我看到了允许访问我的联系人的预期请求。
使用 googleapis 包,然后我使用 Google 用户的访问令牌调用 google.people.connections.list 方法(据我了解,该方法由 contacts.readonly 范围启用)并从我的主要联系人列表中接收人员列表,而不是“其他”联系人列表。
// This is the abstract Google API service config where the user's access token is set
export interface GoogleServiceConfig {
accessToken: string
}
abstract class AbstractGoogleService {
protected _config: GoogleServiceConfig
constructor(config: GoogleServiceConfig) {
this._config = config
}
}
export default AbstractGoogleService
// This is the Google Contacts Helper service that extends the above Abstract Service
export default class GoogleContactsService extends AbstractGoogleService {
// Search for contacts in user's google account and return them as options
async search(options?: any) {
const service = google.people({ version: 'v1', headers: {
// the accessToken is the one fetched from the Google IDP profile provided by the Auth0 management API
authorization: `Bearer ${this._config.accessToken}`
}})
return service.people.connections.list({
resourceName: 'people/me',
pageSize: 100,
personFields: 'names,emailAddresses'
})
}
}
但是,当我向 Google 提交应用范围验证请求时,他们说我只请求 https://www.googleapis.com/auth/contacts.other.readonly 范围,需要修改我的范围验证请求或代码。
我很困惑我应该在哪里请求两个不同的 Google 联系人范围,因为检查 Auth0 Social Google 配置中的联系人框似乎确实请求了 contacts.readonly 范围。
我尝试将两个 Google Scopes 放入我的 handleAuth() 调用中的 [...auth0].ts 中,如此处所示 https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#access-an-external-api-from-an-api-route 但在登录时收到错误...
access_denied (Service not found: https://www.googleapis.com/auth/contacts.readonly https://www.googleapis.com/auth/contacts.other.readonly)
这是我第一次与 Auth0 和 Google API 集成,因此我将不胜感激任何帮助,因为我现在正在兜圈子,并且遇到了正面或反面的麻烦。
谢谢!
【问题讨论】:
标签: next.js google-oauth auth0 google-contacts-api