def oauth_callback(request): """Accept the authorization from the server and store the data we use to communicate with the Weavr""" token = request.REQUEST.get('oauth_token') verifier = request.REQUEST.get('oauth_verifier') confirmed = request.REQUEST.get('oauth_callback_confirmed') # Make sure we have the required parameters if (not verifier) or (not token): return render_error("missing params") if not confirmed: return render_error("connection wasn't confirmed") # Get the token and store the verifier request_token = get_object_or_404(RequestToken, oauth_key=token) if not request_token: return render_error("invalid request token") prosthetic = request_token.prosthetic cls = prosthetic.get_class() if not cls: raise Exception("Can't get class for prosthtic") # verify the token and create a local object verified_token = oauth.OAuthToken(request_token.oauth_key, request_token.oauth_secret) access_token = request_token.prosthetic.wrangler().get_access_token( verified_token, verifier) access_object = AccessToken(oauth_key=access_token.key, oauth_secret=access_token.secret, prosthetic=request_token.prosthetic, enabled=True) # make an API call with the token before we save it. configuration = access_object.get_json("/1/weavr/configuration") access_object.weavr_name = configuration['name'] access_object.weavr_url = configuration['blog'] if "post_keyword" in configuration: access_object.prosthetic.blog_keyword = configuration['post_keyword'] # everything worked. Save access token access_object.save() request_token.delete() # don't need this any more # if the ptk wants to do something at this point, it is able to. ptk = cls(access_object) post_oauth_callback = ptk.post_oauth_callback() if post_oauth_callback: return post_oauth_callback # show or hide user login hide_usernav = True return render_to_response("success.html", locals(), context_instance=RequestContext(request))
def oauth_callback(request): """Accept the authorization from the server and store the data we use to communicate with the Weavr""" token = request.REQUEST.get("oauth_token") verifier = request.REQUEST.get("oauth_verifier") confirmed = request.REQUEST.get("oauth_callback_confirmed") # Make sure we have the required parameters if (not verifier) or (not token): return render_error("missing params") if not confirmed: return render_error("connection wasn't confirmed") # Get the token and store the verifier request_token = get_object_or_404(RequestToken, oauth_key=token) if not request_token: return render_error("invalid request token") prosthetic = request_token.prosthetic cls = prosthetic.get_class() if not cls: raise Exception("Can't get class for prosthtic") # verify the token and create a local object verified_token = oauth.OAuthToken(request_token.oauth_key, request_token.oauth_secret) access_token = request_token.prosthetic.wrangler().get_access_token(verified_token, verifier) access_object = AccessToken( oauth_key=access_token.key, oauth_secret=access_token.secret, prosthetic=request_token.prosthetic, enabled=True ) # make an API call with the token before we save it. configuration = access_object.get_json("/1/weavr/configuration") access_object.weavr_name = configuration["name"] access_object.weavr_url = configuration["blog"] if "post_keyword" in configuration: access_object.prosthetic.blog_keyword = configuration["post_keyword"] # everything worked. Save access token access_object.save() request_token.delete() # don't need this any more # if the ptk wants to do something at this point, it is able to. ptk = cls(access_object) post_oauth_callback = ptk.post_oauth_callback() if post_oauth_callback: return post_oauth_callback # show or hide user login hide_usernav = True return render_to_response("success.html", locals(), context_instance=RequestContext(request))