跳至内容

Google: 通用OAuth2认证#

本文档包含创建通用OAuth2 Google凭证的说明,用于自定义操作

n8n 云用户须知

对于以下节点,您可以通过在OAuth部分选择使用Google登录进行身份验证:

先决条件#

设置OAuth#

将您的n8n凭证连接到Google服务需要五个步骤:

  1. 创建一个Google云控制台项目
  2. 启用API.
  3. 配置您的OAuth同意屏幕
  4. 创建您的Google OAuth客户端凭据
  5. 完成您的n8n凭证

创建一个Google云控制台项目#

首先,创建一个Google云控制台项目。如果您已有项目,请跳转至下一部分:

  1. 使用您的Google账号登录Google Cloud Console
  2. 在顶部菜单中,选择顶部导航栏中的项目下拉菜单并选择新建项目,或直接前往新建项目页面。
  3. 输入项目名称并选择项目的位置
  4. 选择创建
  5. 检查顶部导航栏,确保选择项目下拉菜单中已选中您的项目。如果没有,请选择您刚创建的项目。

    The project dropdown in the Google Cloud top navigation
    检查Google Cloud顶部导航栏中的项目下拉菜单

启用API#

项目创建完成后,启用您需要访问的API:

  1. 访问您的Google Cloud Console - Library。确保您处于正确的项目中。
    The project dropdown in the Google Cloud top navigation
    检查Google Cloud顶部导航栏中的项目下拉菜单
  2. 前往API和服务 > 库
  3. 搜索并选择您想要启用的API。例如,对于Gmail节点,搜索并启用Gmail API。
  4. 某些集成需要其他API或需要您申请访问权限:

    需要Google Drive API

    以下集成需要Google Drive API及其自身的API:

    • Google Docs
    • Google 表格
    • Google 幻灯片

    Google Vertex AI API

    除了Vertex AI API外,您还需要启用Cloud Resource Manager API

  5. 选择启用

如果您之前未在Google Cloud项目中使用过OAuth,您需要配置OAuth同意屏幕

  1. 访问您的Google Cloud Console - Library。确保您处于正确的项目中。
    The project dropdown in the Google Cloud top navigation
    检查Google Cloud顶部导航栏中的项目下拉菜单
  2. 打开左侧导航菜单,进入APIs & 服务 > OAuth 同意屏幕
  3. 对于用户类型,选择内部表示仅限您组织Google工作区内的用户访问,选择外部则表示允许任何拥有Google账号的用户访问。有关用户类型的更多信息,请参阅Google的用户类型文档
  4. 选择创建
  5. Enter the essential information:
    • 应用名称
    • 用户支持邮箱
    • 开发者联系信息中的电子邮箱地址字段
  6. 授权域名部分,如果使用n8n的云服务,请添加n8n.cloud。如果是自托管,请添加您的n8n实例域名。
  7. 选择保存并继续前往数据访问页面并打开添加或删除权限范围
  8. 您无需设置任何范围。再次选择保存并继续进入摘要页面。
  9. 概览页面,检查信息以确保准确性。

创建您的Google OAuth客户端凭据#

接下来,在Google中创建OAuth客户端凭据:

  1. APIs & 服务部分,选择凭据
  2. 选择+ 创建凭证 > OAuth客户端ID
  3. 应用类型下拉菜单中,选择Web应用
  4. Google会自动生成一个名称。将名称更新为您在控制台中能识别的名称。
  5. 从您的n8n凭证中复制OAuth重定向URL。将其粘贴到Google控制台的授权重定向URI中。
  6. 选择创建

完成您的n8n凭证#

在Google项目和凭证完全配置完成后,完成n8n凭证设置:

  1. 从Google的OAuth客户端创建模态窗口中,复制客户端ID。将其输入到您的n8n凭证中。
  2. 从同一个Google模态窗口中,复制客户端密钥。将其输入到您的n8n凭证中。
  3. 您必须为此凭证提供作用域。更多信息请参阅作用域。多个作用域请以空格分隔的列表形式输入,例如:
    1
    https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.action.compose
    
  4. 在n8n中,选择使用Google登录以完成您的Google身份验证。
  5. 保存您的新凭据。

视频#

以下视频演示了上述步骤:

作用域#

Google服务有一个或多个可能的访问范围(scope)。范围限制了用户可以执行的操作。有关所有服务的范围列表,请参阅OAuth 2.0 Scopes for Google APIs

n8n 并不支持所有权限范围。在创建通用 Google OAuth2 API 凭证时,您可以从下方的支持的权限范围列表中选择输入。如果您输入了 n8n 尚未支持的权限范围,它将无法正常工作。

Supported scopes
服务 可用范围
Gmail https://www.googleapis.com/auth/gmail.labels
https://www.googleapis.com/auth/gmail.addons.current.action.compose
https://www.googleapis.com/auth/gmail.addons.current.message.action
https://mail.google.com/
https://www.googleapis.com/auth/gmail.modify
https://www.googleapis.com/auth/gmail.compose
Google广告 https://www.googleapis.com/auth/adwords
Google Analytics https://www.googleapis.com/auth/analytics
https://www.googleapis.com/auth/analytics.readonly
Google BigQuery https://www.googleapis.com/auth/bigquery
谷歌图书 https://www.googleapis.com/auth/books
Google日历 https://www.googleapis.com/auth/calendar
https://www.googleapis.com/auth/calendar.events
Google 云自然语言 https://www.googleapis.com/auth/cloud-language
https://www.googleapis.com/auth/cloud-platform
Google云存储 https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/cloud-platform.read-only
https://www.googleapis.com/auth/devstorage.full_control
https://www.googleapis.com/auth/devstorage.read_only
https://www.googleapis.com/auth/devstorage.read_write
Google 联系人 https://www.googleapis.com/auth/contacts
Google 文档 https://www.googleapis.com/auth/documents
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
Google 云端硬盘 https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.appdata
https://www.googleapis.com/auth/drive.photos.readonly
Google Firebase 云数据库 Firestore https://www.googleapis.com/auth/datastore
https://www.googleapis.com/auth/firebase
Google Firebase 实时数据库 https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/firebase.database
https://www.googleapis.com/auth/firebase
Google Perspective https://www.googleapis.com/auth/userinfo.email
Google Sheets https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/spreadsheets
Google 幻灯片 https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/presentations
Google 任务 https://www.googleapis.com/auth/tasks
Google Translate https://www.googleapis.com/auth/cloud-translation
GSuite 管理员 https://www.googleapis.com/auth/admin.directory.group
https://www.googleapis.com/auth/admin.directory.user
https://www.googleapis.com/auth/admin.directory.domain.readonly
https://www.googleapis.com/auth/admin.directory.userschema.readonly

故障排除#

Google尚未验证此应用#

如果使用OAuth认证方式,您可能会看到警告Google尚未验证此应用。为避免这种情况,您可以从要认证的同一账户创建OAuth凭据。

如需使用其他账户(如开发者或第三方)生成的凭据,请按照Google Cloud文档 | 授权错误:Google尚未验证此应用中的说明操作。

Google Cloud应用授权失效#

对于发布状态设为测试中用户类型设为外部的Google Cloud应用,授权和令牌将在七天后过期。更多信息请参阅Google Cloud Platform Console Help | Setting up your OAuth consent screen。要解决此问题,请在n8n凭据模态窗口中重新连接应用。

优云智算