Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
Trying to get the tokens object from the getToken method but always returning invalid_request
It's giving status: 400 Bad Request
Error (in Browser)
Error (in Terminal)
Error: invalid_request
at Gaxios._request (D:\personal\compy\nylas-app\node_modules\gaxios\build\src\gaxios.js:141:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async OAuth2Client.getTokenAsync (D:\personal\compy\nylas-app\node_modules\google-auth-library\build\src\auth\oauth2client.js:125:21)
at async authorize (webpack-internal:///(api)/./src/pages/api/oauth/connect.ts:15:24) {
digest: undefined
Code
export default async function authorize(
req: NextApiRequest,
res: NextApiResponse,
) {
const { state, code } = req.query as unknown as Record<string, string>;
const { appId } = JSON.parse(state ?? '') as unknown as Record<
string,
string
>;
if (!code || !appId) return res.redirect('/?errorMsg=Server error!');
// Get an access token based on our OAuth code
const { tokens } = await oAuth2Client.getToken(code);
if (!tokens.access_token || !tokens.refresh_token)
return res.redirect('/?errorMsg=Server error!');
// Some logic
return res.redirect('/?successMsg=App created successfully!');
}
Trying to get the tokens object from the
getToken
method but always returninginvalid_request
It's giving status: 400 Bad Request
Error (in Browser)![error](https://github.com/googleapis/google-api-nodejs-client/assets/91947037/fa31a88c-3fa3-4e8b-897e-40c9ce357c4b)
Error (in Terminal)
Code