Oauth2 err depth zero self signed cert

Hi, I have been trying to pass the token from the OAuth2Response node to the https request node using a function to make sure that the refreshed token is passed on. The token is being passed correctly. But I have an error on the OAuth2 node that says, err depth zero self signed cert. If I add "process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" " to the settings.js file, the error changes to "http 400 nok" and the oauth2 object says "invalid scope". Also, the error on the http request says invalid token but that cannot be true since I can see the token is what I want it to be. Just to be sure, isn't this the correct format of specifying the token in the function node,
msg.headers = {
Authorization: "Bearer " + msg.payload
}
I am sure I am missing something that's got to do with self signed certificate. I have the cert and privkey required and also made the required changes in the settings.js file. Also, I have enabled secure TLS connection and added the "pem" files there.
I would really appreciate if someone could help me out here. Thank you in advance!