我希望我的服务帐户能够模拟 GSuite 中的用户之一。
我有
- 通过 GCP 创建项目
- 在项目中启用GMail API
- 向该项目添加了一个服务帐户
- 启用了
domain-wide delegation
在服务帐户设置中GCP
- 添加了一个
API Client
with service account id
通过 Google 管理控制台进行高级设置GSuite
在浏览文档(java)时,我看到了这个
GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("MyProject-1234.json"))
.createScoped(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
.createDelegated("[email protected] /cdn-cgi/l/email-protection");
他们在这里指定服务帐户应模拟哪个用户。这段代码是java中的。我需要在nodejs 中完成同样的事情。
在查看文档时nodejs-client
for googleapis
, 我找到了这个:
const {google} = require('googleapis');
const auth = new google.auth.GoogleAuth({
keyFile: '/path/to/your-secret-key.json',
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
and
const {google} = require('googleapis');
const oauth2Client = new google.auth.OAuth2(
YOUR_CLIENT_ID,
YOUR_CLIENT_SECRET,
YOUR_REDIRECT_URL
);
// set auth as a global default
google.options({
auth: oauth2Client
});
有什么区别GoogleAuth
and OAuth2
here?
如何设置一切以便我的 Node.js 应用程序可以访问[email protected] /cdn-cgi/l/email-protection
通过服务帐户发送邮件?
我如何指定email
我想通过以下方式访问service account
?