custom-components / sensor.trakt

📺 Trakt Integration for Upcoming Media Card
https://trakt.tv/
MIT License
61 stars 14 forks source link

Integration setup returns "The requested redirect uri is malformed or doesn't match client redirect URI.' #34

Closed jayscovill closed 4 years ago

jayscovill commented 4 years ago

Homeassisant version: ,108.6

Integration version: 1.1

Configuration

Configuration.yaml:

trakt: include trakt.yaml:

trakt.yaml:

client_id: !secret trakt_id client_secret: !secret trakt_secret

Describe the bug

When adding the integration the trakt API page returns:

The requested redirect uri is malformed or doesn't match client redirect URI.

https://api-v2launch.trakt.tv/oauth/authorize?response_type=code&client_id=&redirect_uri=http://:8123/auth/external/callback&state=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmbG93X2lkIjoiNDI1ODQwZTkyY2NiNDVjNThmOTMzYzAwZjI5ZTJiMDAifQ.zu3D4s6NO-XzUK1pdeNz4cANz36rPDUpUfjGYAZaIjo

I do have a base_url defined and am using an nginx proxy to allow remote access to Hassio for the mobile app but it is using the internal IP in the callback.

engrbm87 commented 4 years ago

If you can access HA using the internal ip simply add that in the redirect_uri in trakt. (http://:8123/auth/external/callback)

jayscovill commented 4 years ago

Isn’t that already in the URI? Where else would I add it?

engrbm87 commented 4 years ago

You need to put it in the trakt app settings in trakt website.

jayscovill commented 4 years ago

Thanks! That did the trick!

Edit: well almost. Trakt doesn’t appear in the Integrations list after it’s done.

Edit again. OK it is but the display name is mangled and doesn’t contain ‘Trakt.tv’

codeclinic commented 4 years ago

I cannot get my integration to work either. If I use https://mydomain.duckdns.org/auth/external/callback it gives "OAUTH ERROR: The requested redirect uri is malformed or doesn't match client redirect URI".

If I replace the OAUTH redirect uri with my internal ip: http://192.168.178.22:8123/auth/external/callback I get "Missing code or state parameter"

I can't get any further than that.

engrbm87 commented 4 years ago

When you configure the integration check the redirect uri that appears in the new page that opens. Make sure this redirect_uri is configured in the trakt application on trakt website.

codeclinic commented 4 years ago

I've tried all 3 of the following and none of them work:

https://mydomain.duckdns.org/auth/external/callback http://192.168.178.22/auth/external/callback http://192.168.178.22:8123/auth/external/callback

engrbm87 commented 4 years ago

Did you check the redirect_uri that shows in the address bar when a new page opens?

codeclinic commented 4 years ago

I'm not sure what you mean, sorry.

engrbm87 commented 4 years ago

When you create a new Trakt integration you should see a new page opens (just like the page where you got OAUTH error). In that page check the address bar and find the value next to ?redirect_uri=.

codeclinic commented 4 years ago

redirect_uri=http:/mydomain.duckdns.org/auth/external/callback

engrbm87 commented 4 years ago

great, make sure to copy the exact same uri and add it in the trakt application settings (under redirect_uri)

codeclinic commented 4 years ago

If I do do that it just causes a 500 error because the NGINX Proxy redirects to https, and this presumably causes an infinite redirect loop. The NGINX Proxy addon removes the need for a port and makes the site available only via https/domain externally and http/local-ip locally.

engrbm87 commented 4 years ago

if you are using a doamin your base_url should start be https://<your-domain>. This will make the redirect_uri be the same as the base_url.

codeclinic commented 4 years ago

Ok, but the Nginx Proxy addon says to remove that from the config.

codeclinic commented 4 years ago

@engrbm87 So, I added the base url back into to my config then ran the trakt integration process again. This now shows the correct redirect in the QueryString but clicking on authorise just results in a WSOD. Refreshing the page just throws out a 500 error.

However, returning back to the HA Integrations tab shows a "success" message indicating that the integration has been added. I'll see if this now works.

Ming-A commented 1 year ago

Having a similar issue, instead of my cloudflared domain, it shows &redirect_uri=https://my.home-assistant.io/redirect/oauth&state=[a bunch of random letters]. I also get Missing state parameter when it directs me to https://mydomainname.cf/auth/external/callback?code=[random letters and numbers]

ForexTaurus commented 1 year ago

same issue, missing state parameter

MyCPUIsANeuralNetProcessor commented 3 months ago

When you create a new Trakt integration you should see a new page opens (just like the page where you got OAUTH error). In that page check the address bar and find the value next to ?redirect_uri=.

This is the solution for me. I was getting all kinds of problems with 'missing state parameter' trying local ip and external ip. this redirect_uri value was https://my.home-assistant.io/redirect/oauth so i put this into traktv uri link and it worked.