Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Khan API stopped working #141

Open
rexwal opened this issue Jul 15, 2019 · 5 comments
Open

Khan API stopped working #141

rexwal opened this issue Jul 15, 2019 · 5 comments

Comments

@rexwal
Copy link

rexwal commented Jul 15, 2019

Previously working code using OAuthRequester2 started to fail 2 weeks ago (Working for 1 year+)

PHP Notice: Undefined variable: code in /home/sville/public_html/khanmvc/controller/oauth-php/library/OAuthRequester.php on line 485
[15-Jul-2019 10:48:12 Asia/Manila] PHP Fatal error: Uncaught exception 'OAuthException2' with message 'Unexpected result from the server "https://www.khanacademy.org/api/auth/access_token" () while requesting an access token' in /home/sville/public_html/khanmvc/controller/oauth-php/library/OAuthRequester.php:258
Stack trace:

@csilvers
Copy link
Member

csilvers commented Jul 16, 2019 via email

@jb-1980
Copy link
Contributor

jb-1980 commented Jul 18, 2019

I am seeing a similar issue with the Python rauth library. Specifically, it is not parsing correctly the response you provide:

Provider returned: b'OAuth error. Invalid signature. Expected signature base string: POST&https%3A%2F%2Fwww.khanacademy.org%2Fapi%2Fauth2%2Frequest_token&oauth_consumer_key%3D{mykeydedacted}%26oauth_nonce%3D6bded1920bcae508098ef48e58e6df1d22739373%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1563468538%26oauth_version%3D1.0'

However, based on that error message it appears that I am not providing the string you expect.

I have not updated rauth, so I assume it is producing the same base string as before. The only thing I can imagine is that the signature expectation changed on your end?

Anyways, I am currently working on seeing what signature base string rauth is producing. So I can compare it. But I am curious if you have changed anything on your end.

@rexwal
Copy link
Author

rexwal commented Jul 19, 2019

Hi,

We have fixed it. Basically the response code of the server has changed and the OAuthRequester.php wasn't parsing the regex properly.

Will post the solution probs today or tomorrow.

@jb-1980
Copy link
Contributor

jb-1980 commented Jul 19, 2019

I was also able to fix my issue. Once I was able to find what the signature string was that was being produced by the rauth library, I saw one minor difference. It was using http instead of https expected by Khan Academy. After updating my server_url parameter to https://www.khanacademy.org I was able to solve the issue.

While the https protocol have been in the docs since 2015, it seems that enforcing it is recent. My app was working 2 days ago, so I imagine as recent as that.

Also, the api-explorer site is suffering the same bug. I will submit a pull request.

@rexwal
Copy link
Author

rexwal commented Jul 21, 2019

In line 487 of OAuthRequester - I changed this line of code:

          //old code- if (preg_match('@^HTTP/[0-9]\.[0-9] +([0-9]{3})@', $http_line, $matches))
           new code:  if (preg_match('/HTTP\/\d*\.?\d*\s(\d*)/', $http_line, $matches))

This was my solution - editing the ka_example php code posted here.

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

No branches or pull requests

3 participants