简体   繁体   English

如何使用nodejs google api从没有浏览器的EC2实例获取OAuth2令牌

[英]How to get OAuth2 token from an EC2 instance with no browser using nodejs google api

I have a node.js app that uses the google drive API to upload a file to a google drive.我有一个 node.js 应用程序,它使用谷歌驱动器 API 将文件上传到谷歌驱动器。 It is working fine on my local machine.它在我的本地机器上运行良好。 I am now trying to migrate it to an EC2 instance but when I run the app using node, I am unable to verify by visiting the url...我现在正在尝试将它迁移到 EC2 实例,但是当我使用 node 运行应用程序时,我无法通过访问 url 进行验证...

Authorize this app by visiting this url: https://accounts.google.com/o/oauth2/v2/auth ?>access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&cl>ient_id=xxxxxxxxxxxx.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoo>b通过访问此 URL 授权此应用程序: https ://accounts.google.com/o/oauth2/v2/auth ?>access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&cl>ient_id =xxxxxxxxxxxx.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoo>b

Not sure how to proceed as there is no browser on the machine - which makes me question if I am using the correct protocol for this application?不确定如何继续,因为机器上没有浏览器 - 这让我怀疑我是否为此应用程序使用了正确的协议? I get totally confused by all the different options available.我对所有可用的不同选项感到完全困惑。

I am basically using the option laid out here: https://developers.google.com/docs/api/quickstart/nodejs我基本上使用这里列出的选项: https : //developers.google.com/docs/api/quickstart/nodejs

Any pointers would be greatly appreciated.任何指针将不胜感激。

Following the steps from the NodeJs Drive API quickstart , you can run your application locally the first time, this way the consent screen will be prompted and you'll be able to grant the permissions.按照 NodeJs Drive API快速入门中的步骤,您可以第一次在本地运行您的应用程序,这样将提示同意屏幕,您将能够授予权限。 With this, a token.json file will be created in your directory which will be used to create refresh tokens used to authorize the subsequent requests.这样,将在您的目录中创建一个token.json文件,该文件将用于创建用于授权后续请求的刷新令牌。 You can upload your application to the EC2 instance with the token.json file included and you won't have to authorize the application again.您可以将包含token.json文件的应用程序上传到 EC2 实例,而无需再次授权应用程序。

You can read more about refreshing an access token with offline access in Google's OAuth documentation .您可以在 Google 的 OAuth 文档 中阅读有关使用离线访问刷新访问令牌的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 OAuth2 和 PassportJS 获取 Google Fitness API 数据 - How to get Google Fitness API data using OAuth2 with PassportJS 如何从 OAuth2 Google API 获取电子邮件和个人资料信息? - How to get email and profile information from OAuth2 Google API? Ansible Tower API 调用使用来自 Nodejs 应用程序的 OAuth2 令牌 - Ansible Tower API call using OAuth2 Token from Nodejs App 如何使用节点 js 客户端库使用刷新令牌谷歌 oAuth2 获取新的访问令牌 - How to get a new access token using refresh token google oAuth2 using node js client library NodeJS,如何使用谷歌 api 获取带有刷新令牌的新令牌? - NodeJS, How to get new token with refresh token using google api? 从授权码google oauth2获取刷新令牌 - get refresh token from authorization code google oauth2 如何使用 firebase 函数刷新 google oauth2 上的令牌? - how to refresh token on google oauth2 using firebase functions? 使用OAuth2 API时如何存储令牌 - How to store token when using OAuth2 API AWS WebSocket API: how can I invoke API Gateway WebSocket URL from nodejs code running in EC2 instance? - AWS WebSocket API: how can I invoke API Gateway WebSocket URL from nodejs code running in EC2 instance? 使用Passport-google-oauth的OAuth2:GET请求中没有正文,但我仍然收到一些令牌 - OAuth2 using passport-google-oauth: there is no body in GET request but I still recieve some token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM