OAuth NodeJS

Hello everybody! I had in my PHP server an OAUTH connection that I’m replicating i my new NodeJS app.

I’ve literally replicated the action, but i get this error:

{"status":"500","message":"Assignment to constant variable.","stack":"TypeError: Assignment to constant variable.\n at redirect_uri (/opt/node_app/lib/oauth/index.js:128:9)\n at OAuth2.authorize (/opt/node_app/lib/oauth/index.js:57:27)\n at App.authorize (/opt/node_app/lib/modules/oauth.js:28:22)\n at App._exec (/opt/node_app/lib/core/app.js:224:57)\n at App._exec (/opt/node_app/lib/core/app.js:206:28)\n at async App.exec (/opt/node_app/lib/core/app.js:177:9)\n at async App.define (/opt/node_app/lib/core/app.js:160:9)"}

The code is perfect, in fact I’ve copied the whole php file and changed it to be compatible with the NodeJS server.

Thanks!

Seems a bug in the oauth module, please test this update:

index.zip (1.4 KB)

Replace file in lib/oauth.

The bug persists

{"status":"500","message":"opts is not defined","stack":"ReferenceError: opts is not defined\n at OAuth2.authorize (/opt/node_app/lib/oauth/index.js:63:41)\n at App.authorize (/opt/node_app/lib/modules/oauth.js:28:22)\n at App._exec (/opt/node_app/lib/core/app.js:224:57)\n at App._exec (/opt/node_app/lib/core/app.js:206:28)\n at async App.exec (/opt/node_app/lib/core/app.js:177:9)\n at async App.define (/opt/node_app/lib/core/app.js:160:9)"}

Restart the server, otherwise it will not load the new file

Oh, I see now that it is a different error, will check it.

1 Like

Here a new update, hopefully this fixes it.

index.zip (1.4 KB)

Noup

{"status":"500","message":"Cannot read property 'indexOf' of undefined","stack":"TypeError: Cannot read property 'indexOf' of undefined\n at build_url (/opt/node_app/lib/oauth/index.js:124:23)\n at OAuth2.authorize (/opt/node_app/lib/oauth/index.js:63:31)\n at App.authorize (/opt/node_app/lib/modules/oauth.js:28:22)\n at App._exec (/opt/node_app/lib/core/app.js:224:57)\n at App._exec (/opt/node_app/lib/core/app.js:206:28)\n at async App.exec (/opt/node_app/lib/core/app.js:177:9)\n at async App.define (/opt/node_app/lib/core/app.js:160:9)"}

Seems there is more broken then expected, will need some more time for it and do some testing. Will post an update here as soon as possible.

1 Like

Here the latest update

index.zip (1.5 KB)

New error (but at least redirects to google log in session)

Error 400: invalid_request

Invalid parameter value for redirect_uri: Missing authority: localhost:8100/GoogleOAuth

I think this is the latest issue, here the update.

index.zip (1.4 KB)

Almost but nope

{“status”:“500”,“message”:“Http status code 400.”,“stack”:“Error: Http status code 400.\n at IncomingMessage. (/opt/node_app/lib/oauth/index.js:87:39)\n at IncomingMessage.emit (events.js:327:22)\n at endReadableNT (_stream_readable.js:1221:12)\n at processTicksAndRejections (internal/process/task_queues.js:84:21)”}

Did you set all properties correctly, it seems to work for me with google.

Yes, I have the same server connection on php and works fine

It seems to work fine for me and wasn’t able to reproduce the current error. So I edited the file a bit to return some extra information in the error message. At least I hope it returns some useful information.

index.zip (1.5 KB)

This is the error message, but the token is correctly pasted. In fact, the server connection file is exactly the same on the node js app and the php app.

{"status":"500","message":"Http status code 400. {\n \"error\": {\n \"code\": 400,\n \"message\": \"Invalid JSON payload received. Unexpected token.\\ngrant_type=authoriza\\n^\",\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n","stack":"Error: Http status code 400. {\n \"error\": {\n \"code\": 400,\n \"message\": \"Invalid JSON payload received. Unexpected token.\\ngrant_type=authoriza\\n^\",\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n\n at IncomingMessage.<anonymous> (/opt/node_app/lib/oauth/index.js:87:39)\n at IncomingMessage.emit (events.js:327:22)\n at endReadableNT (_stream_readable.js:1221:12)\n at processTicksAndRejections (internal/process/task_queues.js:84:21)"}

Thanks, that error description helped. Having a new update for you.

index.zip (1.5 KB)

Still :frowning:

{“status”:“500”,“message”:“req.setRequestHeader is not a function”,“stack”:“TypeError: req.setRequestHeader is not a function\n at /opt/node_app/lib/oauth/index.js:115:17\n at new Promise ()\n at OAuth2.grant (/opt/node_app/lib/oauth/index.js:78:16)\n at OAuth2.authorize (/opt/node_app/lib/oauth/index.js:51:29)\n at App.authorize (/opt/node_app/lib/modules/oauth.js:28:22)\n at App._exec (/opt/node_app/lib/core/app.js:224:57)\n at App._exec (/opt/node_app/lib/core/app.js:206:28)\n at async App.exec (/opt/node_app/lib/core/app.js:177:9)\n at async App.define (/opt/node_app/lib/core/app.js:160:9)”}

Ah, that should be setHeader, not setRequestHeader.

index.zip (1.5 KB)