This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refresh Token, Web/Public App support (#116)
* Implemented RefreshToken, Public-Web app support for OAuth2.0 * Added unit tests and other small changes Added unit tests for create_payload method, added venv in .gitignore, block of code for setting redirectURI was misplaced * Added a unit test, fixed bugs Added the test_authToken_should_differ_if_refresh_token_is_enforced unit test, fixed two bugs in client.py * Updated the README.md file * Renamed a test method and added a class docstring for the test class * Addressed code review requested changes * Updated SDK version from 1.2.0 to 1.3.0 Updated SDK version from 1.2.0 to 1.3.0 in FuelSDK/__init__.py, client.py, rest.py and setup.py * Added tests config * Small changes in FuelSDK/Public_WebAppTests/test_ET_Client.py Replaced the setUp with setUpClass and updated the docstring
- Loading branch information
1 parent
34eb519
commit 40c9379
Showing
9 changed files
with
236 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[Web Services] | ||
appsignature: none | ||
clientid: <CLIENT_ID> | ||
clientsecret: <CLIENT_SECRET> | ||
defaultwsdl: https://webservice.exacttarget.com/etframework.wsdl | ||
authenticationurl: <AUTH TENANT SPECIFIC ENDPOINT> | ||
wsdl_file_local_loc: <WSDL_PATH>/ExactTargetWSDL.xml | ||
|
||
[Auth Service] | ||
useOAuth2Authentication: True | ||
accountId: <TARGET_ACCOUNT_ID> | ||
scope: <PERMISSION_LIST> | ||
applicationType: <APPLICATION_TYPE> | ||
redirectURI: <REDIRECT_URI_FOR_PUBLIC/WEB_APP> | ||
authorizationCode: <AUTHORIZATION_CODE_FOR_PUBLIC/WEB_APP> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from unittest import TestCase | ||
from FuelSDK import ET_Client | ||
|
||
|
||
class TestET_Client(TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
""" | ||
test_authToken_and_refreshKey_should_differ_if_refresh_token_is_enforced expects a Public/Web App config. | ||
All the other tests require a Server to Server config | ||
""" | ||
|
||
cls.client = ET_Client(False, False) | ||
|
||
def test_authToken_and_refreshKey_should_differ_if_refresh_token_is_enforced(self): | ||
self.authToken1 = self.client.authToken | ||
self.refreshKey1 = self.client.refreshKey | ||
|
||
self.client.refresh_token_with_oAuth2(True) | ||
|
||
self.authToken2 = self.client.authToken | ||
self.refreshKey2 = self.client.refreshKey | ||
|
||
self.assertNotEqual(self.authToken1, self.authToken2) | ||
self.assertNotEqual(self.refreshKey1, self.refreshKey2) | ||
|
||
def test_auth_payload_should_have_public_app_attributes(self): | ||
self.client.application_type = 'public' | ||
|
||
payload = self.client.create_payload() | ||
|
||
self.assertEqual(self.client.client_id, payload['client_id']) | ||
self.assertEqual(self.client.redirect_URI, payload['redirect_uri']) | ||
self.assertEqual(self.client.authorization_code, payload['code']) | ||
self.assertEqual('authorization_code', payload['grant_type']) | ||
|
||
def test_auth_payload_for_public_app_should_not_have_client_secret(self): | ||
self.client.application_type = 'public' | ||
|
||
payload = self.client.create_payload() | ||
|
||
self.assertRaises(KeyError, lambda: payload['client_secret']) | ||
|
||
def test_auth_payload_should_have_web_app_attributes(self): | ||
self.client.application_type = 'web' | ||
|
||
payload = self.client.create_payload() | ||
|
||
self.assertEqual('authorization_code', payload['grant_type']) | ||
self.assertEqual(self.client.client_id, payload['client_id']) | ||
self.assertEqual(self.client.client_secret, payload['client_secret']) | ||
self.assertEqual(self.client.redirect_URI, payload['redirect_uri']) | ||
self.assertEqual(self.client.authorization_code, payload['code']) | ||
|
||
def test_auth_payload_should_have_server_app_attributes(self): | ||
self.client.application_type = 'server' | ||
|
||
payload = self.client.create_payload() | ||
|
||
self.assertEqual('client_credentials', payload['grant_type']) | ||
self.assertEqual(self.client.client_id, payload['client_id']) | ||
self.assertEqual(self.client.client_secret, payload['client_secret']) | ||
|
||
def test_auth_payload_for_server_app_should_not_have_code_and_redirect_uri(self): | ||
self.client.application_type = 'server' | ||
|
||
payload = self.client.create_payload() | ||
|
||
self.assertRaises(KeyError, lambda: payload['code']) | ||
self.assertRaises(KeyError, lambda: payload['redirect_uri']) | ||
|
||
def test_auth_payload_with_refresh_token_should_have_refresh_token_attribute(self): | ||
self.client.refreshKey = 'RefreshKey' | ||
|
||
payload = self.client.create_payload() | ||
|
||
self.assertEqual('refresh_token', payload['grant_type']) | ||
self.assertEqual(self.client.refreshKey, payload['refresh_token']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters