1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import rauth, rauth.service, base64, os

for line in os.environ["REQUEST_URI"].split("?")[1].split("&"):
        GET[line.split("=")[0]] = line.split("=")[1]

reddit = rauth.service.OAuth2Service(
        name="reddit",
        consumer_key='cust-kry',
        consumer_secret='secret',
        access_token_url="https://ssl.reddit.com/api/v1/access_token",
        authorize_url="https://ssl.reddit.com/api/v1/authorize")
print "Content-Type: text/html;charset=utf-8"
print
try:
    response = reddit.get_access_token(
        auth=(reddit.consumer_key, reddit.consumer_secret),
        data=dict(
            grant_type="authorization_code",
            code=GET["code"],
            redirect_uri='forward.py'))
    print GET["code"] + "<br />"
    print response.content
except:
    print "Unexpected error:", sys.exc_info()