Skip to content

Commit d319617

Browse files
authored
Merge pull request #203 from umbraco/feature/manually-exchange-authorization-code-for-access-token
Add feature for manually exchange an authorization code for a token
2 parents 9e17517 + c879799 commit d319617

File tree

4 files changed

+63
-27
lines changed

4 files changed

+63
-27
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
background-color: #eee;
2020
}
2121

22-
.hsFormsList a i {
23-
position: absolute;
24-
top: .4rem;
25-
left: .25rem;
26-
}
22+
.hsFormsList a i {
23+
position: absolute;
24+
top: .4rem;
25+
left: .25rem;
26+
}
2727

2828
.hsFormsList .formLine {
2929
display: block;
@@ -33,4 +33,11 @@
3333
padding-top: 4px;
3434
}
3535

36+
#authCode {
37+
display: none;
38+
}
3639

40+
#inAuthCode {
41+
width: 40%;
42+
margin: 0 auto;
43+
}

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/settings.controller.js

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@
3939

4040
vm.onConnectClick = function () {
4141

42-
window.addEventListener("message", getAccessToken, false);
42+
window.addEventListener("message", handleOAuthSuccess, false);
4343
umbracoCmsIntegrationsCrmHubspotResource.getAuthorizationUrl().then(function (response) {
4444
vm.authWindow = window.open(response,
4545
"Authorize", "width=900,height=700,modal=yes,alwaysRaised=yes");
4646

47+
// check in 7 seconds for authorization window closed
48+
setTimeout(() => {
49+
if (vm.authWindow && !vm.authWindow.closed) {
50+
toggleAuthCodeSection(true);
51+
}
52+
}, 7000);
4753
});
4854
}
4955

@@ -62,26 +68,40 @@
6268
});
6369
}
6470

65-
function getAccessToken(event) {
71+
vm.onAuthorize = function () {
72+
getAccessToken(vm.authCode);
73+
}
74+
75+
function handleOAuthSuccess(event) {
6676
if (event.data.type === "hubspot:oauth:success") {
67-
umbracoCmsIntegrationsCrmHubspotResource.getAccessToken(event.data.code).then(function (response) {
68-
vm.authEventHandled = true;
77+
getAccessToken(event.data.code);
78+
}
79+
}
6980

70-
if (response.startsWith("Error:")) {
71-
if (typeof $scope.connected === "undefined")
72-
notificationsService.error("HubSpot Configuration", response);
73-
} else {
74-
vm.oauthSetup.isConnected = true;
75-
vm.status.description = umbracoCmsIntegrationsCrmHubspotService.configDescription.OAuthConnected;
81+
function getAccessToken(code) {
82+
if (!code || code.length == 0) {
83+
notificationsService.warning("HubSpot Configuration", "Please add a valid authentication code.");
84+
return;
85+
}
7686

77-
if (typeof $scope.connected === "undefined")
78-
notificationsService.success("HubSpot Configuration", "OAuth connected.");
87+
umbracoCmsIntegrationsCrmHubspotResource.getAccessToken(code).then(function (response) {
88+
vm.authEventHandled = true;
89+
toggleAuthCodeSection(false);
7990

80-
if (typeof $scope.connected === "function")
81-
$scope.connected();
82-
}
83-
});
84-
}
91+
if (response.startsWith("Error:")) {
92+
if (typeof $scope.connected === "undefined")
93+
notificationsService.error("HubSpot Configuration", response);
94+
} else {
95+
vm.oauthSetup.isConnected = true;
96+
vm.status.description = umbracoCmsIntegrationsCrmHubspotService.configDescription.OAuthConnected;
97+
98+
if (typeof $scope.connected === "undefined")
99+
notificationsService.success("HubSpot Configuration", "OAuth connected.");
100+
101+
if (typeof $scope.connected === "function")
102+
$scope.connected();
103+
}
104+
});
85105
}
86106

87107
function validateOAuthSetup() {
@@ -105,6 +125,10 @@
105125

106126
});
107127
}
128+
129+
function toggleAuthCodeSection(isVisible) {
130+
document.getElementById("authCode").style.display = isVisible ? "block" : "none";
131+
}
108132
}
109133

110134
angular.module("umbraco")

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/views/settings.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@
1818
disabled="!vm.oauthSetup.isConnected">
1919
</umb-button>
2020
</div>
21+
<div id="authCode" class="mt3">
22+
<input id="inAuthCode" type="text" ng-model="vm.authCode" placeholder="Authorization code" no-dirty-check />
23+
<umb-button action="vm.onAuthorize()"
24+
type="button"
25+
button-style="primary"
26+
state="init"
27+
label="Authorize">
28+
</umb-button>
29+
</div>
2130
</div>

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

Lines changed: 1 addition & 5 deletions
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.Hubspot</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/umbraco/Umbraco.Cms.Integrations</RepositoryUrl>
13-
<Version>4.0.2</Version>
13+
<Version>4.0.3</Version>
1414
<Authors>Umbraco HQ</Authors>
1515
<Company>Umbraco</Company>
1616
<PackageTags>Umbraco;Umbraco-Marketplace</PackageTags>
@@ -60,10 +60,6 @@
6060
</Content>
6161
</ItemGroup>
6262

63-
<ItemGroup>
64-
<None Remove="App_Plugins\UmbracoCms.Integrations\Crm\Hubspot\js\hubspotauthorization.directive.js" />
65-
</ItemGroup>
66-
6763
<ItemGroup>
6864
<Content Include="hubspot.png">
6965
<Pack>true</Pack>

0 commit comments

Comments
 (0)