Oauth "We were unable to complete this request."

I made an app that uses OAuth to authenticate and then later use the Plex API, it worked well until pretty recently. I was already authenticated in my app but requests weren’t working. I’ll figure out why local API requests are failing after I figure out auth again.

SO I cleared the auth token I had cached and went to trigger oauth again to get a fresh one., first it (seemingly successfully) fetches a code and id from:
https://plex.tv/api/v2/pins.json?strong=true

Then builds a URL to open to do the authentication:
https://app.plex.tv/auth#?context[device][product]=Posterizer&context[device][environment]=bundled&context[device][layout]=desktop&context[device][platform]=Web&context[device][device]=Posterizer%20(Web)&clientID=xxxxxxxxxx&forwardUrl=xxxxxxxxx&code=whhyc7wan68k1n1uil3xxxxxx
(I replaced some stuff with xxxxx for this post)

Here’s how I built that URL:

var login_url =
      'https://app.plex.tv/auth#' +
      `?context[device][product]=${product}` +
      '&context[device][environment]=bundled' +
      '&context[device][layout]=desktop' +
      `&context[device][platform]=${platform}` +
      `&context[device][device]=${encodeURI(device)}` +
      `&clientID=${clientId}` +
      `&forwardUrl=${redirectUri}` +
      `&code=${code}`;

When the URL opens in a browser window it says “We were unable to complete this request. You will be redirected automatically.” and redirects me to the plex homepage (which for the record isn’t my forwardURL)

Did something change with oauth recently? I notice in THIS POST that recently a Plex Employee was trying to track down a “We were unable to complete this request.” problem, but the context of the issue is slightly different. I disabled 2FA on my account to see if that for some weird reason would do anything, it didn’t. I tried logging out of Plex then trying the flow, didn’t work. I’ve tried on more than one computer. I don’t really know what else to try as my oauth flow has been working great since I wrote it back in June but now it just isn’t.

I’d appreciate any assistance I can get.

Thanks,
Zac

I was having the same issue. For some reason, it looks like the forwardUrl parameter is what is causing issues.
If you remove it from your URL, it should work.
But that means you’ll need to get the authToken using polling, instead of forwarding.

I’ll give that a try when I get home- if I remember correctly I already don’t actually rely on the forward URL so it might work out for me? Maybe I’m wrong though and I will need the forward :stuck_out_tongue:

Thank you! I do indeed already use polling, I detect when the popup window closes then it polls for the auth token. So because of that removing the forward URL param worked perfectly!

1 Like

Has anybody out figured out if it’s possible to make this work? When you authenticate a local PMS via Plex Web it used forwardUrl with a localhost, so I can’t imagine they are screening forwardUrl for valid values. Are they perhaps rejecting usages of forwardUrl based on something else then and, if so, has anybody been able to determine what?

I am using forwardUrl and it’s unclear how I could change that without quite a large change in approach.

Actually, I think I may have just figured it out! I searched the auth-form JS for the string "We were unable to complete this request.", searched around the nearby code, and was able to step through the code where the auth form fetches and handles response of GET https://plex.tv/api/v2/pins/info?code=....

By looking at the response of GET https://plex.tv/api/v2/pins/info?code=..., I noticed that the origin field was null, but the code which handles the response specifically checks that the Origin and the forwardUrl's hostname are the same:

So, I tried adding Origin: header to the initial pin creation POST https://plex.tv/api/v2/pins?strong=true request and voila I was redirected to my forwardUrl!

@duncanbeeversAdmin I wonder if it is worth amending Authenticating with Plex to reflect this requirement for people planning to make use of forwardUrl?

Cheers,
Bo

1 Like