Skip to content

Commit e20f0f6

Browse files
Add processing of target account property (#54)
* target account id for python * added processing of target account ID --------- Signed-off-by: Anna Hileta <[email protected]> Co-authored-by: Paige Rossi <[email protected]>
1 parent 788dcaa commit e20f0f6

File tree

5 files changed

+61
-15
lines changed

5 files changed

+61
-15
lines changed

OAuth/code_grant.php

+29-9
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,34 @@
7575
file_put_contents($outputFile, $accessToken);
7676
echo "\nAccess token has been written to " . $outputFile . "\n\n";
7777

78-
$userInfo = http(
79-
$authorizationEndpoint . 'userinfo', false, [
80-
'Authorization: Bearer ' . $accessToken]
78+
$userInfo = http($authorizationEndpoint . 'userinfo', false,
79+
[
80+
'Authorization: Bearer ' . $accessToken
81+
]
8182
);
82-
// impersonation user guid
83-
// var_dump($userInfo->sub);
84-
$APIAccountId = $userInfo->accounts[0]->account_id;
85-
file_put_contents($apiAccountIdFile, $APIAccountId);
86-
echo "Account id: $APIAccountId\n";
87-
echo "Account id has been written to config/API_ACCOUNT_ID file...\n\n";
83+
84+
if ($TARGET_ACCOUNT_ID != "{TARGET_ACCOUNT_ID}") {
85+
$targetAccountFound = false;
86+
foreach ($userInfo->accounts as $account_info) {
87+
if ($account_info->account_id == $TARGET_ACCOUNT_ID) {
88+
$APIAccountId = $account_info->account_id;
89+
$targetAccountFound = true;
90+
break;
91+
}
92+
}
93+
if (! $targetAccountFound) {
94+
throw new Exception("Targeted Account with Id " . $TARGET_ACCOUNT_ID . " not found.");
95+
}
96+
} else {
97+
foreach ($userInfo->accounts as $account_info) {
98+
if ($account_info->is_default) {
99+
$APIAccountId = $account_info->account_id;
100+
break;
101+
}
102+
}
103+
}
104+
105+
file_put_contents($apiAccountIdFile, $APIAccountId);
106+
echo "Account id: $APIAccountId\n";
107+
echo "Account id has been written to config/API_ACCOUNT_ID file...\n\n";
88108
?>

OAuth/jwt.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,24 @@
136136
]
137137
);
138138

139-
$APIAccountId = $userInfo->accounts[0]->account_id;
140-
file_put_contents('config/API_ACCOUNT_ID', $APIAccountId);
141-
139+
if ($TARGET_ACCOUNT_ID != "{TARGET_ACCOUNT_ID}") {
140+
$targetAccountFound = false;
141+
foreach ($userInfo->accounts as $account_info) {
142+
if ($account_info->account_id == $TARGET_ACCOUNT_ID) {
143+
file_put_contents('config/API_ACCOUNT_ID', $account_info->account_id);
144+
$targetAccountFound = true;
145+
break;
146+
}
147+
}
148+
if (! $targetAccountFound) {
149+
throw new Exception("Targeted Account with Id " . $TARGET_ACCOUNT_ID . " not found.");
150+
}
151+
} else {
152+
foreach ($userInfo->accounts as $account_info) {
153+
if ($account_info->is_default) {
154+
file_put_contents('config/API_ACCOUNT_ID', $account_info->account_id);
155+
break;
156+
}
157+
}
158+
}
142159
?>

OAuth/jwt_auth.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,15 @@ def _write_token(cls, scopes):
109109

110110
user_info = api_client.get_user_info(cls.ds_app.access_token)
111111
accounts = user_info.get_accounts()
112-
api_account_id = open("./config/API_ACCOUNT_ID", "w")
113-
api_account_id.write(accounts[0].account_id)
114-
api_account_id.close()
112+
target_account_id = os.environ.get('TARGET_ACCOUNT_ID')
113+
if target_account_id != "{TARGET_ACCOUNT_ID}":
114+
api_account_id = open("./config/API_ACCOUNT_ID", "w")
115+
api_account_id.write(target_account_id)
116+
api_account_id.close()
117+
else:
118+
api_account_id = open("./config/API_ACCOUNT_ID", "w")
119+
api_account_id.write(accounts[0].account_id)
120+
api_account_id.close()
115121

116122

117123
@staticmethod

OAuth/utils.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
$INTEGRATION_KEY_JWT = getenv("INTEGRATION_KEY_JWT");
1313
$IMPERSONATION_USER_GUID = getenv("IMPERSONATION_USER_GUID");
14+
$TARGET_ACCOUNT_ID = getenv("TARGET_ACCOUNT_ID");
1415

1516
$authorizationEndpoint = 'https://account-d.docusign.com/oauth/';
1617

config/settings.example.txt

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ export INTEGRATION_KEY_AUTH_CODE="{INTEGRATION_KEY_AUTH_CODE}"
1010
export SECRET_KEY="{SECRET_KEY}"
1111
export GATEWAY_ACCOUNT_ID="{DS_PAYMENT_GATEWAY_ID}"
1212
export QUICKSTART="{QUICKSTART_VALUE}"
13+
export TARGET_ACCOUNT_ID="{TARGET_ACCOUNT_ID}"
14+

0 commit comments

Comments
 (0)