Skip to content

Commit d27fa90

Browse files
authored
[FBE.js] Delete unnecessary 'exchange access token' code (#521)
1 parent 33c7f7e commit d27fa90

File tree

5 files changed

+28
-111
lines changed

5 files changed

+28
-111
lines changed

app/code/Meta/BusinessExtension/Block/Adminhtml/Setup.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,6 @@ public function getFirstWebsiteId()
362362
return $collection->getFirstItem()->getWebsiteId();
363363
}
364364

365-
/**
366-
* Get fbe access token url endpoint
367-
*
368-
* @return string
369-
*/
370-
public function getFbeAccessTokenUrl()
371-
{
372-
return $this->fbeHelper->getFbeAccessTokenUrl();
373-
}
374-
375365
/**
376366
* Get fbe installs config url endpoint
377367
*

app/code/Meta/BusinessExtension/Helper/FBEHelper.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,4 @@ public function checkAdminEndpointPermission()
452452
}
453453
}
454454

455-
/**
456-
* Get fbe access token url endpoint
457-
*
458-
* @return string
459-
*/
460-
public function getFbeAccessTokenUrl()
461-
{
462-
$apiVersion = $this->graphAPIAdapter->getGraphApiVersion();
463-
if (!$apiVersion) {
464-
return null;
465-
}
466-
$baseUrl = $this->getGraphBaseURL();
467-
return "{$baseUrl}/{$apiVersion}/business_manager_id/access_token";
468-
}
469455
}

app/code/Meta/BusinessExtension/view/adminhtml/templates/setup.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
externalBusinessId: '<?=
2323
$escaper->escapeHtml($block->getExternalBusinessId($block->getSelectedStoreId()))
2424
?>',
25-
fbeAccessTokenUrl: '<?= $escaper->escapeHtml($block->getFbeAccessTokenUrl()) ?>',
2625
fbeInstallsConfigUrl: '<?= $escaper->escapeHtml($block->getFbeInstallsConfigUrl()) ?>',
2726
fbeInstallsSaveUrl: '<?= $escaper->escapeHtml($block->getFbeInstallsSaveUrl()) ?>',
2827
fbeLoginUrl: '<?= $escaper->escapeHtml($block->getSplashPageURL()) ?>',

app/code/Meta/BusinessExtension/view/adminhtml/web/js/fbe_allinone.js

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ var IEOverlay = require('./IEOverlay');
152152
var FBModal = require('./Modal');
153153
var FBUtils = require('./utils');
154154

155-
const accessTokenScope = ['manage_business_extension', 'business_management', 'ads_management', 'pages_read_engagement', 'catalog_management'];
156-
157155
var jQuery = (function (jQuery) {
158156
if (jQuery && typeof jQuery === 'function') {
159157
return jQuery;
@@ -201,7 +199,7 @@ jQuery(document).ready(function() {
201199
},
202200

203201
bindMessageEvents: function bindMessageEvents() {
204-
var _this = this;
202+
const _this = this;
205203
if (FBUtils.isIE() && window.MessageChannel) {
206204
// do nothing, wait for our messaging utils to be ready
207205
} else {
@@ -240,7 +238,6 @@ jQuery(document).ready(function() {
240238
if (action === 'create' || messageEvent === 'CommerceExtension::INSTALL') {
241239
const success = message.success;
242240
if (success) {
243-
const businessManagerId = message.business_manager_id;
244241
const accessToken = message.access_token;
245242
const pixelId = message.pixel_id;
246243
const profiles = message.profiles;
@@ -250,7 +247,7 @@ jQuery(document).ready(function() {
250247
const installedFeatures = message.installed_features;
251248

252249
_this.savePixelId(pixelId);
253-
_this.exchangeAccessToken(accessToken, businessManagerId);
250+
_this.saveAccessToken(accessToken);
254251
_this.saveProfilesData(profiles);
255252
_this.saveAAMSettings(pixelId);
256253
_this.saveConfig(accessToken, catalogId, pageId, commercePartnerIntegrationId);
@@ -272,7 +269,7 @@ jQuery(document).ready(function() {
272269
}
273270
},
274271
savePixelId: function savePixelId(pixelId) {
275-
var _this = this;
272+
const _this = this;
276273
if (!pixelId) {
277274
console.error('Meta Business Extension Error: got no pixel_id');
278275
return;
@@ -302,15 +299,15 @@ jQuery(document).ready(function() {
302299
});
303300
},
304301
saveAccessToken: function saveAccessToken(accessToken) {
305-
var _this = this;
302+
const _this = this;
306303
if (!accessToken) {
307304
console.error('Meta Business Extension Error: got no access token');
308305
return;
309306
}
310307
jQuery.ajax({
311308
type: 'post',
312309
url: ajaxify(window.facebookBusinessExtensionConfig.setAccessToken),
313-
async : false,
310+
async: false,
314311
data: ajaxParam({
315312
accessToken: accessToken,
316313
}),
@@ -322,34 +319,8 @@ jQuery(document).ready(function() {
322319
}
323320
});
324321
},
325-
exchangeAccessToken: function exchangeAccessToken(access_token, business_manager_id) {
326-
const _this = this;
327-
const fbeAccessTokenUrl = window.facebookBusinessExtensionConfig.fbeAccessTokenUrl;
328-
if (!fbeAccessTokenUrl) {
329-
console.error('Could not exchange access token. Token url not found.');
330-
return;
331-
}
332-
let requestData = {
333-
'access_token': access_token,
334-
'app_id': window.facebookBusinessExtensionConfig.appId,
335-
'fbe_external_business_id': window.facebookBusinessExtensionConfig.externalBusinessId,
336-
'scope': accessTokenScope.join()
337-
};
338-
jQuery.ajax({
339-
type: 'post',
340-
url: fbeAccessTokenUrl.replace("business_manager_id", business_manager_id),
341-
async : false,
342-
data: requestData,
343-
success: function onSuccess(data, _textStatus, _jqXHR) {
344-
_this.saveAccessToken(data.access_token);
345-
},
346-
error: function () {
347-
console.error('There was an error getting access_token');
348-
}
349-
});
350-
},
351322
saveProfilesData: function saveProfilesData(profiles) {
352-
var _this = this;
323+
const _this = this;
353324
if (!profiles) {
354325
console.error('Meta Business Extension Error: got no profiles data');
355326
return;
@@ -370,8 +341,8 @@ jQuery(document).ready(function() {
370341
});
371342
},
372343
saveAAMSettings: function saveAAMSettings(pixelId){
373-
var _this = this;
374-
jQuery.ajax({
344+
const _this = this;
345+
jQuery.ajax({
375346
'type': 'post',
376347
url: ajaxify(window.facebookBusinessExtensionConfig.setAAMSettings),
377348
async : false,
@@ -392,7 +363,7 @@ jQuery(document).ready(function() {
392363
});
393364
},
394365
saveInstalledFeatures: function saveInstalledFeatures(installedFeatures) {
395-
var _this = this;
366+
const _this = this;
396367
if (!installedFeatures) {
397368
console.error('Meta Business Extension Error: got no installed_features data');
398369
return;
@@ -417,7 +388,7 @@ jQuery(document).ready(function() {
417388
});
418389
},
419390
cleanConfigCache : function cleanConfigCache() {
420-
var _this = this;
391+
const _this = this;
421392
jQuery.ajax({
422393
type: 'post',
423394
url: ajaxify(window.facebookBusinessExtensionConfig.cleanConfigCacheUrl),
@@ -434,7 +405,7 @@ jQuery(document).ready(function() {
434405
});
435406
},
436407
saveConfig: function saveConfig(accessToken, catalogId, pageId, commercePartnerIntegrationId) {
437-
var _this = this;
408+
const _this = this;
438409
jQuery.ajax({
439410
type: 'post',
440411
url: ajaxify(window.facebookBusinessExtensionConfig.saveConfig),
@@ -458,7 +429,7 @@ jQuery(document).ready(function() {
458429
});
459430
},
460431
postFBEOnboardingSync: function postFBEOnboardingSync() {
461-
var _this = this;
432+
const _this = this;
462433
jQuery.ajax({
463434
type: 'post',
464435
url: ajaxify(window.facebookBusinessExtensionConfig.postFBEOnboardingSync),
@@ -477,8 +448,8 @@ jQuery(document).ready(function() {
477448
});
478449
},
479450
deleteFBAssets: function deleteFBAssets() {
480-
var _this = this;
481-
jQuery.ajax({
451+
const _this = this;
452+
jQuery.ajax({
482453
type: 'delete',
483454
url: ajaxify(window.facebookBusinessExtensionConfig.deleteConfigKeys),
484455
data: ajaxParam({

app/code/Meta/BusinessExtension/view/adminhtml/web/js/lib/fbe.js

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ var IEOverlay = require('./IEOverlay');
1414
var FBModal = require('./Modal');
1515
var FBUtils = require('./utils');
1616

17-
const accessTokenScope = ['manage_business_extension', 'business_management', 'ads_management', 'pages_read_engagement', 'catalog_management'];
18-
1917
var jQuery = (function (jQuery) {
2018
if (jQuery && typeof jQuery === 'function') {
2119
return jQuery;
@@ -63,7 +61,7 @@ jQuery(document).ready(function() {
6361
},
6462

6563
bindMessageEvents: function bindMessageEvents() {
66-
var _this = this;
64+
const _this = this;
6765
if (FBUtils.isIE() && window.MessageChannel) {
6866
// do nothing, wait for our messaging utils to be ready
6967
} else {
@@ -102,7 +100,6 @@ jQuery(document).ready(function() {
102100
if (action === 'create' || messageEvent === 'CommerceExtension::INSTALL') {
103101
const success = message.success;
104102
if (success) {
105-
const businessManagerId = message.business_manager_id;
106103
const accessToken = message.access_token;
107104
const pixelId = message.pixel_id;
108105
const profiles = message.profiles;
@@ -112,7 +109,7 @@ jQuery(document).ready(function() {
112109
const installedFeatures = message.installed_features;
113110

114111
_this.savePixelId(pixelId);
115-
_this.exchangeAccessToken(accessToken, businessManagerId);
112+
_this.saveAccessToken(accessToken);
116113
_this.saveProfilesData(profiles);
117114
_this.saveAAMSettings(pixelId);
118115
_this.saveConfig(accessToken, catalogId, pageId, commercePartnerIntegrationId);
@@ -134,7 +131,7 @@ jQuery(document).ready(function() {
134131
}
135132
},
136133
savePixelId: function savePixelId(pixelId) {
137-
var _this = this;
134+
const _this = this;
138135
if (!pixelId) {
139136
console.error('Meta Business Extension Error: got no pixel_id');
140137
return;
@@ -164,15 +161,15 @@ jQuery(document).ready(function() {
164161
});
165162
},
166163
saveAccessToken: function saveAccessToken(accessToken) {
167-
var _this = this;
164+
const _this = this;
168165
if (!accessToken) {
169166
console.error('Meta Business Extension Error: got no access token');
170167
return;
171168
}
172169
jQuery.ajax({
173170
type: 'post',
174171
url: ajaxify(window.facebookBusinessExtensionConfig.setAccessToken),
175-
async : false,
172+
async: false,
176173
data: ajaxParam({
177174
accessToken: accessToken,
178175
}),
@@ -184,34 +181,8 @@ jQuery(document).ready(function() {
184181
}
185182
});
186183
},
187-
exchangeAccessToken: function exchangeAccessToken(access_token, business_manager_id) {
188-
const _this = this;
189-
const fbeAccessTokenUrl = window.facebookBusinessExtensionConfig.fbeAccessTokenUrl;
190-
if (!fbeAccessTokenUrl) {
191-
console.error('Could not exchange access token. Token url not found.');
192-
return;
193-
}
194-
let requestData = {
195-
'access_token': access_token,
196-
'app_id': window.facebookBusinessExtensionConfig.appId,
197-
'fbe_external_business_id': window.facebookBusinessExtensionConfig.externalBusinessId,
198-
'scope': accessTokenScope.join()
199-
};
200-
jQuery.ajax({
201-
type: 'post',
202-
url: fbeAccessTokenUrl.replace("business_manager_id", business_manager_id),
203-
async : false,
204-
data: requestData,
205-
success: function onSuccess(data, _textStatus, _jqXHR) {
206-
_this.saveAccessToken(data.access_token);
207-
},
208-
error: function () {
209-
console.error('There was an error getting access_token');
210-
}
211-
});
212-
},
213184
saveProfilesData: function saveProfilesData(profiles) {
214-
var _this = this;
185+
const _this = this;
215186
if (!profiles) {
216187
console.error('Meta Business Extension Error: got no profiles data');
217188
return;
@@ -232,8 +203,8 @@ jQuery(document).ready(function() {
232203
});
233204
},
234205
saveAAMSettings: function saveAAMSettings(pixelId){
235-
var _this = this;
236-
jQuery.ajax({
206+
const _this = this;
207+
jQuery.ajax({
237208
'type': 'post',
238209
url: ajaxify(window.facebookBusinessExtensionConfig.setAAMSettings),
239210
async : false,
@@ -254,7 +225,7 @@ jQuery(document).ready(function() {
254225
});
255226
},
256227
saveInstalledFeatures: function saveInstalledFeatures(installedFeatures) {
257-
var _this = this;
228+
const _this = this;
258229
if (!installedFeatures) {
259230
console.error('Meta Business Extension Error: got no installed_features data');
260231
return;
@@ -279,7 +250,7 @@ jQuery(document).ready(function() {
279250
});
280251
},
281252
cleanConfigCache : function cleanConfigCache() {
282-
var _this = this;
253+
const _this = this;
283254
jQuery.ajax({
284255
type: 'post',
285256
url: ajaxify(window.facebookBusinessExtensionConfig.cleanConfigCacheUrl),
@@ -296,7 +267,7 @@ jQuery(document).ready(function() {
296267
});
297268
},
298269
saveConfig: function saveConfig(accessToken, catalogId, pageId, commercePartnerIntegrationId) {
299-
var _this = this;
270+
const _this = this;
300271
jQuery.ajax({
301272
type: 'post',
302273
url: ajaxify(window.facebookBusinessExtensionConfig.saveConfig),
@@ -320,7 +291,7 @@ jQuery(document).ready(function() {
320291
});
321292
},
322293
postFBEOnboardingSync: function postFBEOnboardingSync() {
323-
var _this = this;
294+
const _this = this;
324295
jQuery.ajax({
325296
type: 'post',
326297
url: ajaxify(window.facebookBusinessExtensionConfig.postFBEOnboardingSync),
@@ -339,8 +310,8 @@ jQuery(document).ready(function() {
339310
});
340311
},
341312
deleteFBAssets: function deleteFBAssets() {
342-
var _this = this;
343-
jQuery.ajax({
313+
const _this = this;
314+
jQuery.ajax({
344315
type: 'delete',
345316
url: ajaxify(window.facebookBusinessExtensionConfig.deleteConfigKeys),
346317
data: ajaxParam({

0 commit comments

Comments
 (0)