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

Examples/flask_test_client not working #144

Open
hieyou1 opened this issue Aug 13, 2019 · 1 comment
Open

Examples/flask_test_client not working #144

hieyou1 opened this issue Aug 13, 2019 · 1 comment

Comments

@hieyou1
Copy link

hieyou1 commented Aug 13, 2019

Hi there,

When I try to access the Khan API thru the flask test client, it says that it "expected a signature base string." I tried fixes I found in other issues but it still isn't working. Here's the error:
KeyError: "Decoder failed to handle oauth_token with data as returned by provider. A different decoder may be needed. Provider returned: b'OAuth error. Invalid signature. Expected signature base string: POST&https%3A%2F%2Fwww.khanacademy.org%2Fapi%2Fauth2%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A5000%252Foauth_callback%26oauth_consumer_key%3DMY-KEY%26oauth_nonce%3Df8cfed8b74ebfb911d733e2ea40e5076d9260ebe%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1565700706%26oauth_version%3D1.0'"

Here's my changed khan_api file. I only remember changing the http to https, but there may be more. {Server.py left unchanged}

"""
This example script shows a possible method for integrating the Khan API into
a flask server
"""

from rauth import OAuth1Service
import requests
from flask import url_for, request, redirect, session
from time import time
import json

# You can get a CONSUMER_KEY and CONSUMER_SECRET for your app here:
# http://www.khanacademy.org/api-apps/register
CONSUMER_KEY = "MY KEY"
CONSUMER_SECRET = "MY SECRET"

# Oauth configuration values described at:
# https://github.com/Khan/khan-api/wiki/Khan-Academy-API-Authentication
SERVER_URL = "https://www.khanacademy.org"
REQUEST_TOKEN_URL = SERVER_URL + "/api/auth2/request_token"
ACCESS_TOKEN_URL = SERVER_URL + "/api/auth2/access_token"
AUTHORIZE_URL = SERVER_URL + "/api/auth2/authorize"
BASE_URL = SERVER_URL + "/api/auth2"

I have no idea what is going on. Doesn't work with PHP either (different error), but I'm not really interested in PHP.

@jb-1980
Copy link
Contributor

jb-1980 commented Aug 27, 2019

When I started the server I saw the exact same error. But when I applied your change (modified the SERVER_URL variable to use https instead of http) the issue was resolved. Are you still seeing this issue?

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

2 participants