Skip to content

Commit 89b0572

Browse files
authored
Merge pull request #45 from umbraco/bugfix/dynamics-property-editor
Handle oauth success event raised multiple times
2 parents dcf8f4e + 6438fd6 commit 89b0572

File tree

3 files changed

+33
-25
lines changed

3 files changed

+33
-25
lines changed

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/configuration.controller.js

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var vm = this;
33

44
vm.oauthConfig = {};
5+
vm.oauthSuccessEventCount = 0;
56

67
umbracoCmsIntegrationsCrmDynamicsResource.checkOAuthConfiguration().then(function (response) {
78
if (response && response.isAuthorized) {
@@ -39,30 +40,34 @@
3940
// authorization listener
4041
window.addEventListener("message", function (event) {
4142
if (event.data.type === "hubspot:oauth:success") {
42-
43-
umbracoCmsIntegrationsCrmDynamicsResource.getAccessToken(event.data.code).then(function (response) {
44-
if (response.startsWith("Error:")) {
45-
46-
// if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window.
47-
// if directive runs from data type, the notifications are displayed
48-
if (typeof $scope.connected === "undefined")
49-
notificationsService.error("Dynamics Configuration", response);
50-
} else {
51-
vm.oauthConfig.isConnected = true;
52-
53-
// if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window.
54-
// if directive runs from data type, the notifications are displayed
55-
if (typeof $scope.connected === "undefined")
56-
notificationsService.success("Dynamics Configuration", "OAuth connected.");
57-
58-
umbracoCmsIntegrationsCrmDynamicsResource.getSystemUserFullName().then(function(response) {
59-
vm.oauthConfig.fullName = response;
60-
});
61-
62-
if (typeof $scope.connected === "function")
63-
$scope.connected();
64-
}
65-
});
43+
vm.oauthSuccessEventCount += 1;
44+
45+
if (vm.oauthSuccessEventCount == 1) {
46+
umbracoCmsIntegrationsCrmDynamicsResource.getAccessToken(event.data.code).then(function (response) {
47+
48+
if (response.startsWith("Error:")) {
49+
50+
// if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window.
51+
// if directive runs from data type, the notifications are displayed
52+
if (typeof $scope.connected === "undefined")
53+
notificationsService.error("Dynamics Configuration", response);
54+
} else {
55+
vm.oauthConfig.isConnected = true;
56+
57+
// if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window.
58+
// if directive runs from data type, the notifications are displayed
59+
if (typeof $scope.connected === "undefined")
60+
notificationsService.success("Dynamics Configuration", "OAuth connected.");
61+
62+
umbracoCmsIntegrationsCrmDynamicsResource.getSystemUserFullName().then(function (response) {
63+
vm.oauthConfig.fullName = response;
64+
});
65+
66+
if (typeof $scope.connected === "function")
67+
$scope.connected();
68+
}
69+
});
70+
}
6671
}
6772
}, false);
6873
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/Controllers/FormsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public async Task<string> GetAccessToken([FromBody] OAuthRequestDto authRequestD
124124
var errorResult = await response.Content.ReadAsStringAsync();
125125
var errorDto = JsonConvert.DeserializeObject<ErrorDto>(errorResult);
126126

127-
return "Error: " + errorDto.Message;
127+
return "Error: " + errorDto.ErrorDescription;
128128
}
129129

130130
return "Error: An unexpected error occurred.";

src/Umbraco.Cms.Integrations.Crm.Dynamics/Models/Dtos/ErrorDto.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ public class ErrorDto
99

1010
[JsonProperty("message")]
1111
public string Message { get; set; }
12+
13+
[JsonProperty("error_description")]
14+
public string ErrorDescription { get; set; }
1215
}
1316
}

0 commit comments

Comments
 (0)