-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use code to obtain token. During the process of auth2, the request https://oauth2.googleapis.com/token failed. #3450
Comments
After testing, it was found that this interface https://oauth2.googleapis.com/token There is a problem, this interface does not support SHH requests, and using curl and so on results in the same error. The following error message: curl: (28) Failed to connect to oauth2. googleapis.com port 443 after 227030 ms: Couldn't connect to server The execution code is as follows: I found this interface https://oauth2.googleapis.com/token Many people are now giving feedback that I obtain my token access_token through the JWT token, but this interface does not support SSH, which prevents me from obtaining tokens on the node side. The project can only be terminated or alternative solutions can be used. To be clear, the interface https://oauth2.googleapis.com/token Unsupported SSH caused node |
I couldn't find the corresponding entry in [support console] and couldn't start, so I'm still here to ask for help.
I use [email protected] in my node project, the code is as follows:
const { google } = require('googleapis');
async getToken() {
const { ctx } = this;
const { code } = ctx.request.body;
const { client_id, client_secret, redirect_uri, } = ctx.app.config.oauth2Google;
const oauth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uri);
const data = await oauth2Client.getToken(code);
}
Wrong question:
config: {"method":"POST","url":"https://oauth2.googleapis.com/token","data":"< - See
errorRedactor
option ingaxios
for configuration >.","headers":{"Content-Type":"application/x-www-form-urlencoded","User-Agent":"google-api-nodejs-client/9.6.3","x- goog-api-client":"gl-node/20.11.0"},"body":"< - SeeerrorRedactor
option ingaxios
for configuration>.","responseType":"unknown" }response: undefined
error: {"message":"request to https://oauth2.googleapis.com/token failed, reason: read ECONNRESET","type":"system","errno":"ECONNRESET","code":" ECONNRESET"}
Here is the official documentation: https://developers.google.com/identity/protocols/oauth2/web-server?hl=zh-cn#exchange-authorization-code
and code:
`const url = require('url');
// Receive the callback from Google's OAuth 2.0 server.
if (req.url.startsWith('/oauth2callback')) {
// Handle the OAuth 2.0 server response
let q = url.parse(req.url, true).query;
// Get access and refresh tokens (if access_type is offline)
let { tokens } = await oauth2Client.getToken(q.code);
oauth2Client.setCredentials(tokens);
}`
Thanks!
The text was updated successfully, but these errors were encountered: