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

POST Request to /api/identity-provider/login failed from browser with [missing]identityProviderId Error #875

Closed
ShehabSN opened this issue Sep 17, 2020 · 9 comments

Comments

@ShehabSN
Copy link

ShehabSN commented Sep 17, 2020

POST Request to /api/identity-provider/login failed from browser with [missing]identityProviderId Error

Description

So I was implementing a custom google login flow following along with the Docs (https://fusionauth.io/docs/v1/tech/apis/identity-providers/google). So my client app has a google auth button and it basically triggers the pop up and the user signs up/logs in. This is not related to FusionAuth yet until I send the id_token from that successful login , which I successfully received and logged, to the /api/identity-provider/login endpoint as stated in the docs. In my POST request, I include all the required information including the id_token, applicationId, and the identityProviderId for Google straight from the docs and my provider instance in my FusionAuth dashboard as you can see below.

fetch("http://localhost:9011/api/identity-provider/login", {
  method: "POST",
  body: JSON.stringify({
    data: {
      token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    },
    identityProviderId: "82339786-3dff-42a6-aac6-1f1ceecb6c46",
    applicationId: "XXXXXXXXXXXXXXXX",
  }),
})
  .then((res) => res.json())
  .then((result) => console.log(result))
  .catch((err) => {
    console.log(err);
  });

For some reason when I run this from my browser which is CORS enabled and my Fusion Auth application also has Google Provider enabled I get the below error. I have no idea what the actual problem is since I clearly have the identityProviderId listed exactly as how it was stated in the docs. If i remove all the other information from the request I still get the same error. What is very weird is that when I make this exact same request from Postman desktop, it works perfectly and I get back the expected response. What could be the problem here, and why am I getting such an unrelated error which makes it virtually impossible to debug?

{
	"fieldErrors": {
		"identityProviderId": [
			{
				"code": "[missing]identityProviderId",
				"message": "You must specify the [identityProviderId] property."
			}
		]
	}
}
@robotdan
Copy link
Member

You can try adding mode: 'no-cors' to your request to see if that changes your result.

If that doesn't help, you can generate a HAR file of the request, this will likely tell you what is happening.
https://www.medianova.com/en-blog/2019/07/15/a-step-by-step-guide-to-generating-a-har-file

You can also make sure you have allowed your request origin in the FusionAuth CORS configuration if you have not yet done so. https://fusionauth.io/docs/v1/tech/reference/cors

@ShehabSN
Copy link
Author

ShehabSN commented Sep 18, 2020

I tried adding the mode: 'no-cors to the request and I got the same result.

I checked the HAR file and it unfortunately doesn't show me anything new, the same 400 Code and same missing identityproviderid error.

I had the wildcard * set for allowed origins from the cors configuration in fusion auth and it still wont work. I even tried just writing the frontend url instead of the wildcard and still no luck. Am i missing any request headers that should be enabled or something? The allowed request headers are the same as default. Not sure what is going on and I have no clue how to debug, seems like a bug since the error message is completely unrelated.

@elskhn
Copy link

elskhn commented Sep 18, 2020

I am facing the same issue. Trying to issue a POST to the /api/identity-provider/login after successfully signing in with Google. My request includes the required parameters as defined in : https://fusionauth.io/docs/v1/tech/apis/identity-providers/google#complete-the-google-login but the response is still a 400 Bad Request with the same error as @ShehabSN.

@robotdan
Copy link
Member

@ShehabSN can you post your HAR file?

@ShehabSN
Copy link
Author

ShehabSN commented Sep 18, 2020

@robotdan I can email you a redacted one if that's okay

@robotdan
Copy link
Member

Sent you a LinkedIn message w/ my email.

@robotdan
Copy link
Member

I looked your HAR file, the Content-Type HTTP header on the POST request is text/plain;charset=utf-8 instead of application/json. Try adding this header explicitly to your request.

@ShehabSN
Copy link
Author

Added that as a header and it works now, thanks!

@mooreds
Copy link
Collaborator

mooreds commented Sep 18, 2020

https://fusionauth.io/community/forum/topic/407/missing-identityproviderid-error

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

No branches or pull requests

4 participants