@@ -88,7 +88,7 @@ can be easily translated to a web application.
88
88
# having the user authorize an access token and to sign the request to obtain
89
89
# said access token.
90
90
91
- resp, content = client.request(request_token_url, "GET ")
91
+ resp, content = client.request(request_token_url, "POST", body="oauth_callback=oob ")
92
92
if resp['status'] != '200':
93
93
raise Exception("Invalid response %s." % resp['status'])
94
94
@@ -218,7 +218,7 @@ and code here might need to be updated if you are using Python 2.6+.
218
218
219
219
def twitter_login(request):
220
220
# Step 1. Get a request token from Twitter.
221
- resp, content = client.request(request_token_url, "POST", body=urlencode({' oauth_callback':"/"} )
221
+ resp, content = client.request(request_token_url, "POST", body=" oauth_callback=http://<base-URL>login/authenticated/" )
222
222
if resp['status'] != '200':
223
223
raise Exception("Invalid response from Twitter.")
224
224
@@ -243,10 +243,14 @@ and code here might need to be updated if you are using Python 2.6+.
243
243
# Step 1. Use the request token in the session to build a new client.
244
244
token = oauth.Token(request.session['request_token']['oauth_token'],
245
245
request.session['request_token']['oauth_token_secret'])
246
+
247
+ if 'oauth_verifier' in request.GET:
248
+ token.set_verifier(request.GET['oauth_verifier'])
249
+
246
250
client = oauth.Client(consumer, token)
247
251
248
252
# Step 2. Request the authorized access token from Twitter.
249
- resp, content = client.request(access_token_url, "GET ")
253
+ resp, content = client.request(access_token_url, "POST ")
250
254
if resp['status'] != '200':
251
255
print content
252
256
raise Exception("Invalid response from Twitter.")
@@ -272,10 +276,16 @@ and code here might need to be updated if you are using Python 2.6+.
272
276
# These two things will likely never be used. Alternatively, you
273
277
# can prompt them for their email here. Either way, the password
274
278
# should never be used.
275
- user = User.objects.create_user(access_token['screen_name'],
276
- '%[email protected] ' % access_token['screen_name'],
277
- access_token['oauth_token_secret'])
278
-
279
+
280
+
281
+ user = User.objects.create_user(username=access_token['screen_name'],
282
+ email='%[email protected] ' % access_token['screen_name'],
283
+ password=access_token['oauth_token_secret'])
284
+ # Need to reset password because set_password saves the password as a hash
285
+ # whereas the constructor above saves plaintext
286
+ user.set_password(access_token['oauth_token_secret'])
287
+ user.save()
288
+
279
289
# Save our permanent token and secret for later.
280
290
profile = Profile()
281
291
profile.user = user
0 commit comments