def testget(self): oauth.get('CODE', dwollaparse='dict') oauth.r._post_without_token.assert_any_call('/token/', { 'code': 'CODE', 'client_secret': 'SOME SECRET', 'grant_type': 'authorization_code', 'client_id': 'SOME ID' }, {'dwollaparse': 'dict'}, custompostfix='/oauth/v2')
def get(self, request, *args, **kwargs): self.object = self.get_object() if 'code' in request.GET: redirect_url = request.build_absolute_uri( reverse('brambling_dwolla_connect')) api_type = request.GET['api'] dwolla_prep(api_type) redirect_url = dwolla_redirect_url( self.object, api_type, request, next_url=request.GET.get('next_url')) oauth_tokens = oauth.get(request.GET['code'], redirect=redirect_url) if 'access_token' in oauth_tokens: token = oauth_tokens['access_token'] # Now get account info. account_info = accounts.full(token) try: account = DwollaAccount.objects.get( api_type=api_type, user_id=account_info['Id']) except DwollaAccount.DoesNotExist: account = DwollaAccount(api_type=api_type, user_id=account_info['Id']) account.set_tokens(oauth_tokens) account.save() if self.object.get_dwolla_account(api_type) != account: if api_type == LIVE: self.object.dwolla_account = account else: self.object.dwolla_test_account = account self.object.save() messages.success(request, "Dwolla account connected!") elif 'error_description' in oauth_tokens: messages.error(request, oauth_tokens['error_description']) else: messages.error(request, "Unknown error during dwolla connection.") elif 'error_description' in request.GET: messages.error(request, request.GET['error_description']) else: messages.error(request, "Unknown error during dwolla connection.") return HttpResponseRedirect(self.get_success_url())
def get(self, request, *args, **kwargs): self.object = self.get_object() redirect_url = self.object.get_dwolla_connect_url() api_type = request.GET['api'] if 'code' in request.GET: qs = request.GET.copy() del qs['code'] if qs: redirect_url += "?" + "&".join([k + "=" + v for k, v in qs.iteritems()]) dwolla_prep(api_type) oauth_tokens = oauth.get(request.GET['code'], redirect=request.build_absolute_uri(redirect_url)) if 'access_token' in oauth_tokens: token = oauth_tokens['access_token'] # Now get account info. account_info = accounts.full(token) if api_type == LIVE: self.object.dwolla_user_id = account_info['Id'] else: self.object.dwolla_test_user_id = account_info['Id'] dwolla_set_tokens(self.object, api_type, oauth_tokens) self.object.save() messages.success(request, "Dwolla account connected!") elif 'error_description' in oauth_tokens: messages.error(request, oauth_tokens['error_description']) else: messages.error(request, "Unknown error during dwolla connection.") elif 'error_description' in request.GET: messages.error(request, request.GET['error_description']) else: messages.error(request, "Unknown error during dwolla connection.") return HttpResponseRedirect(self.get_success_url())
# # http://requestb.in is a service that catches # redirect responses. Go over to their URL and make # your own so that you may conveniently catch the # redirect parameters. # # You can view your responses at: # http://requestb.in/[some_id]?inspect # # If you're feeling dangerous, feel free to simply use # http://google.com and manually parse the parameters # out yourself. The choice remains yours. print oauth.genauthurl("http://requestb.in/yxlywryx") # Step 2: The redirect should provide you with a `code` # parameter. You will now exchange this code for an access # and refresh token pair. access_set = oauth.get("Z/KHDIyWO/LboIGn3wGGs1+sRWg=", "http://requestb.in/yxlywryx") print access_set # Step 2.5: If you wish, you can set the library's global # access token parameter by doing the following... constants.access_token=access_set['access_token'] # Step 3: Exchange your expiring refresh token for another # access/refresh token pair.x print oauth.refresh(access_set['refresh_token'])
def testget(self): oauth.get('CODE', dwollaparse='dict') oauth.r._post_without_token.assert_any_call('/token/', {'code': 'CODE', 'client_secret': 'SOME SECRET', 'grant_type': 'authorization_code', 'client_id': 'SOME ID'}, {'dwollaparse': 'dict'}, custompostfix='/oauth/v2')
# You can view your responses at: # http://requestb.in/[some_id]?inspect # # If you're feeling dangerous, feel free to simply use # http://google.com and manually parse the parameters # out yourself. The choice remains yours. print(oauth.genauthurl("http://requestb.in/122rdhc1")) # Step 2: The redirect should provide you with a `code` # parameter. You will now exchange this code for an access # and refresh token pair. access_set = oauth.get("Z/KHDIyWO/LboIGn3wGGs1+sRWg=", "http://requestb.in/122rdhc1") print(access_set) # Step 2.5: If you wish, you can set the library's global # access token parameter by doing the following... constants.access_token = access_set['access_token'] # Step 3: Exchange your expiring refresh token for another # access/refresh token pair.x access_set = oauth.refresh(access_set['refresh_token']) print(access_set) # Step 4: Retrieve the catalog of endpoints that # are available to the OAuth token which you just
def testget(self): oauth.get('CODE') oauth.r._post.assert_any_call('/token/', {'code': 'CODE', 'client_secret': 'SOME SECRET', 'grant_type': 'authorization_code', 'client_id': 'SOME ID'}, '/oauth/v2', 'dict')