Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
"What could be the reason for encountering a 'Socket Hang Up' error when dealing with OAuth 2.0 Redirect URL Issue in a React App and Node.js Backend, despite successfully receiving a response in Postman, especially when using Node.js POST method?"

I'm currently working on implementing OAuth 2.0 in my React application for user authorization, with a Node.js backend serving as a proxy server for API calls to the authentication provider. However, after a successful login on the authorization server's page, the redirect URL specified in my Node.js configuration isn't generating a token, and I'm encountering a "socket hang up" error.

I've tried to address this issue by configuring my Node.js server to use HTTPS and adding certificates. Here's my configuration:

REACT_APP_SERVER_URL = https://127.0.0.1:55555
REDIRECT_URI = http://127.0.0.1:55555/login

In the documentation for my OIDC authorization code flow, I've come across the requirement that "The Client must validate the server’s identity based on the server's TLS certificate." I am following this recommendation, but the issue persists.

I cant change REDIRECT_URI to use HTTPS manually by using https://127.0.0.1:55555/login
Can anyone provide guidance on how to resolve this issue and ensure successful token generation after a successful login?

What I have tried:

JavaScript
const response = await axios.post(tokenEndpoint, tokenRequestParams.toString(), {
			headers: {
				Authorization: Authorization,
				'Content-Type': 'application/x-www-form-urlencoded'
			}
Posted
Comments
Dave Kreskowiak 9-Oct-23 9:42am    
Check the header values PostMan is sending against the headers your code is sending. I'd be willing to bet there's they are different.
Jithu_007 9-Oct-23 10:07am    
No headers are constant for every request like const Authorization = `Basic ${Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString('base64')}`; to postman i am taking value from console.so all params and headers double checked.I am doubting http/https issue mentioned in my question.no idea how to solve

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900