Skip to content
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

ERROR: Cannot read property 'split' of undefined #735

Closed
Laazarus opened this issue Jul 7, 2020 · 8 comments
Closed

ERROR: Cannot read property 'split' of undefined #735

Laazarus opened this issue Jul 7, 2020 · 8 comments

Comments

@Laazarus
Copy link

Laazarus commented Jul 7, 2020

Describe the bug
I created Oauth2 credentials for LinkedIn and I tested the connection giving the authorisation, Everything worked showing that the connection was successful. When I use the credentials in a HTTP Request node I get the exception ERROR: Cannot read property 'split' of undefined

To Reproduce
Steps to reproduce the behavior:

  1. Create a Oauth2 credentials with LinkedIn data
  2. Click to connect the credentials and allow the app
  3. Create an http request node and use the credentials created to perform a LinkedIn API request (in my case share a post)
  4. Execute the workflow passing data to the http request node

Expected behavior
I would expect that the authentication with LinkedIn using the credentials created would succeed

Environment (please complete the following information):

  • Ubuntu 20.04 LTS
  • n8n Version 0.72.0
  • Node.js Version v10.19.0
@janober
Copy link
Member

janober commented Jul 8, 2020

Thanks a lot for reporting this issue.

Can you please post the whole error message. It should probably also display the stack trace in the node. Thanks!

@Laazarus
Copy link
Author

Laazarus commented Jul 8, 2020

Hello @janober,

Thanks for your fast answer and the great platform that is n8n.

Here is the stack trace on the node:

ERROR: Cannot read property 'split' of undefined
TypeError: Cannot read property 'split' of undefined
    at ClientOAuth2Token.sign (/usr/local/lib/node_modules/n8n/node_modules/client-oauth2/src/client-oauth2.js:339:35)
    at Object.requestOAuth2 (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/NodeExecuteFunctions.js:57:37)
    at Object.requestOAuth2 (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/NodeExecuteFunctions.js:393:42)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest.node.js:730:65)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:570:37)
    at returnPromise (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:370:62)

Please let me know if I can help any further

@Laazarus
Copy link
Author

Laazarus commented Jul 8, 2020

Hello,

I have investigated the code a bit and I see that the

requestObject.url

is undefined while

requestObject.uri

is defined.
Also Linked in tokentype is not marked as bearer so the line of code

 if (this.tokenType === 'bearer') {
    requestObject.headers.Authorization = 'Bearer ' + this.accessToken
  } else {

Goes in the else part causing the issue.

I modified the code in this way:

 if (this.tokenType === 'bearer'|| !this.tokenType) {
    requestObject.headers.Authorization = 'Bearer ' + this.accessToken
  } else {

and it seems to work but I am not sure I am causing other issues down the line with this assumption. I thought this might help to know though.

Thanks again...

@RicardoE105
Copy link
Contributor

@Laazarus yes, this has happened to my a couple of times, this happens cuz according to the standard when getting the accessToken the endpoint should return the token type as well, and it should be bearer, some of the companies do not do this, and the library it's expecting that tokenType = 'bearer'. That is why it failed.

Maybe with a condition, after the token exchange, like if the response does not include token type, then we add it manually.

Your approach works but you had to modify the npm package.

@RicardoE105 RicardoE105 added the bug label Jul 8, 2020
@Laazarus
Copy link
Author

Laazarus commented Jul 8, 2020

Hello @RicardoE105 ,

Thanks for your answer, yes that was my intention with that fix. Basically if we are dealing with APIs that do not respect the standards (AKA LinkedIn) We set as default the type as Bearer.
How can I do without modifying the token type without modifying the npm package? The authorisation handshacke happens when I make an HTTP Request in the HTTP Request node.
IS there a better way I can do?
Best Regards

RicardoE105 added a commit to RicardoE105/n8n that referenced this issue Jul 9, 2020
janober pushed a commit that referenced this issue Jul 10, 2020
@janober
Copy link
Member

janober commented Aug 2, 2020

Can you please check with the latest version if that issue is fixed now? Thanks!

@janober
Copy link
Member

janober commented Aug 14, 2020

Closing this issue now. If you are still having this problem simply comment here.

@janober janober closed this as completed Aug 14, 2020
@Murilobdo
Copy link

I'm having the same problem, I call an api but if I print the result on the first line I already get this message

(node: 18288) UnhandledPromiseRejectionWarning: Error: TypeError: Cannot read property
'split' of undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants