Skip to content

Commit f9446b6

Browse files
authored
Merge pull request #204 from umbraco/feature/dynamics-manually-exchange-auth-code-for-access-token
Add feature to manually exchange auth codes
2 parents d319617 + 83448ef commit f9446b6

File tree

4 files changed

+68
-26
lines changed

4 files changed

+68
-26
lines changed

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/css/styles.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,13 @@
3535

3636
.dynFormSelected {
3737
background: #fee4e1;
38+
}
39+
40+
#authCode {
41+
display: none;
42+
}
43+
44+
#inAuthCode {
45+
width: 40%;
46+
margin: 0 auto;
3847
}

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

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121

2222
vm.onConnectClick = function () {
2323

24-
window.addEventListener("message", getAccessToken, false);
24+
window.addEventListener("message", handleOAuthSuccess, false);
2525
umbracoCmsIntegrationsCrmDynamicsResource.getAuthorizationUrl().then(function (response) {
2626
vm.authWindow = window.open(response,
2727
"Authorize", "width=900,height=700,modal=yes,alwaysRaised=yes");
28+
29+
// check in 7 seconds for authorization window closed
30+
setTimeout(() => {
31+
if (vm.authWindow && !vm.authWindow.closed) {
32+
toggleAuthCodeSection(true);
33+
}
34+
}, 7000);
2835
});
2936
}
3037

@@ -45,33 +52,50 @@
4552
});
4653
}
4754

48-
function getAccessToken(event) {
55+
vm.onAuthorize = function () {
56+
getAccessToken(vm.authCode);
57+
}
58+
59+
function getAccessToken(code) {
60+
if (!code || code.length == 0) {
61+
notificationsService.warning("Dynamics Configuration", "Please add a valid authentication code.");
62+
return;
63+
}
64+
65+
umbracoCmsIntegrationsCrmDynamicsResource.getAccessToken(event.data.code).then(function (response) {
66+
if (response.startsWith("Error:")) {
67+
68+
// if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window.
69+
// if directive runs from data type, the notifications are displayed
70+
if (typeof $scope.connected === "undefined")
71+
notificationsService.error("Dynamics Configuration", response);
72+
} else {
73+
vm.oauthConfig.isConnected = true;
74+
75+
// if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window.
76+
// if directive runs from data type, the notifications are displayed
77+
if (typeof $scope.connected === "undefined")
78+
notificationsService.success("Dynamics Configuration", "OAuth connected.");
79+
80+
umbracoCmsIntegrationsCrmDynamicsResource.getSystemUserFullName().then(function (response) {
81+
vm.oauthConfig.fullName = response;
82+
});
83+
84+
if (typeof $scope.connected === "function")
85+
$scope.connected();
86+
}
87+
});
88+
}
89+
90+
function handleOAuthSuccess(event) {
4991
if (event.data.type === "dynamics:oauth:success") {
50-
umbracoCmsIntegrationsCrmDynamicsResource.getAccessToken(event.data.code).then(function (response) {
51-
if (response.startsWith("Error:")) {
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.error("Dynamics Configuration", response);
57-
} else {
58-
vm.oauthConfig.isConnected = true;
59-
60-
// if directive runs from property editor, the notifications should be hidden, because they will not be displayed properly behind the overlay window.
61-
// if directive runs from data type, the notifications are displayed
62-
if (typeof $scope.connected === "undefined")
63-
notificationsService.success("Dynamics Configuration", "OAuth connected.");
64-
65-
umbracoCmsIntegrationsCrmDynamicsResource.getSystemUserFullName().then(function (response) {
66-
vm.oauthConfig.fullName = response;
67-
});
68-
69-
if (typeof $scope.connected === "function")
70-
$scope.connected();
71-
}
72-
});
92+
getAccessToken(event.data.code);
7393
}
7494
}
95+
96+
function toggleAuthCodeSection(isVisible) {
97+
document.getElementById("authCode").style.display = isVisible ? "block" : "none";
98+
}
7599
}
76100

77101
angular.module("umbraco")

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/configuration.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@
2424
</umb-button>
2525
</div>
2626
</div>
27+
<div id="authCode" class="mt3">
28+
<input id="inAuthCode" type="text" ng-model="vm.authCode" placeholder="Authorization code" no-dirty-check />
29+
<umb-button action="vm.onAuthorize()"
30+
type="button"
31+
button-style="primary"
32+
state="init"
33+
label="Authorize">
34+
</umb-button>
35+
</div>
2736
</div>

src/Umbraco.Cms.Integrations.Crm.Dynamics/Umbraco.Cms.Integrations.Crm.Dynamics.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageIconUrl></PackageIconUrl>
1111
<PackageProjectUrl>https://github.com/umbraco/Umbraco.Cms.Integrations/blob/main/src/Umbraco.Cms.Integrations.Crm.Dynamics</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/umbraco/Umbraco.Cms.Integrations</RepositoryUrl>
13-
<Version>1.3.4</Version>
13+
<Version>1.3.5</Version>
1414
<Authors>Umbraco HQ</Authors>
1515
<Company>Umbraco</Company>
1616
<PackageTags>Umbraco;Umbraco-Marketplace</PackageTags>

0 commit comments

Comments
 (0)