def django_exchange_token(request): # ask the oauth server to exchange a request token into an access token # this will check proper oauth for this action try: access_token = OAUTH_SERVER.exchange_request_token(djangoutils.extract_request(request)) except OAuthError: # an exception can be raised if there is a bad signature (or no signature) in the request pass return HttpResponse(access_token.to_string())
def django_protected_view(request): """ A Django view that is oauth authenticated """ try: # oauth_parameters will be all of the oauth parameters, including core (timestamp) and non-core (sudo). consumer, token, oauth_parameters = OAUTH_SERVER.check_resource_access(djangoutils.extract_request(request)) except OAuthError: # a permission error pass
def django_request_token(request): """ the request-token request URL """ # ask the oauth server to generate a request token given the HTTP request try: request_token = OAUTH_SERVER.generate_request_token(djangoutils.extract_request(request)) except OAuthError: # an exception can be raised if there is a bad signature (or no signature) in the request pass return HttpResponse(request_token.to_string())