Skip to content

Commit 16c1c3d

Browse files
committed
OAuth updates
1 parent 91f028d commit 16c1c3d

File tree

5 files changed

+282
-269
lines changed

5 files changed

+282
-269
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
.hsFormsList a i {
2222
position: absolute;
23-
top: .5rem;
23+
top: .4rem;
2424
left: .25rem;
2525
}
2626

src/Umbraco.Cms.Integrations.Crm.Hubspot/Configuration/AppSettingsConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public static class AppSettingsConstants
99

1010
public static string UmbracoCmsIntegrationsCrmHubspotOAuthScopes = "Umbraco.Cms.Integrations.Crm.Hubspot.OAuthScopes";
1111

12+
public static string UmbracoCmsIntegrationsCrmHubspotOAuthAuthorizationBaseUrl =
13+
"Umbraco.Cms.Integrations.Crm.Hubspot.OAuthAuthorizationBaseUrl";
14+
1215
public static string UmbracoCmsIntegrationsCrmHubspotOAuthRedirectUrl = "Umbraco.Cms.Integrations.Crm.Hubspot.OAuthRedirectUrl";
1316

1417
public static string UmbracoCmsIntegrationsOAuthProxyUrl = "Umbraco.Cms.Integrations.OAuthProxyUrl";

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,17 @@ public async Task<string> GetAccessToken([FromBody] OAuthRequestDto authRequestD
186186
var data = new Dictionary<string, string>
187187
{
188188
{"grant_type", "authorization_code"},
189-
{"client_id", ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.Crm.Hubspot.OAuthClientId"]},
189+
{"client_id", _appSettings[AppSettingsConstants.UmbracoCmsIntegrationsCrmHubspotOAuthClientId] },
190190
{
191-
"redirect_uri",
192-
ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.Crm.Hubspot.OAuthRedirectUrl"]
191+
"redirect_uri", _appSettings[AppSettingsConstants.UmbracoCmsIntegrationsCrmHubspotOAuthRedirectUrl]
193192
},
194193
{ "code", authRequestDto.Code }
195194
};
196195

197196
var requestMessage = new HttpRequestMessage
198197
{
199198
Method = HttpMethod.Post,
200-
RequestUri = new Uri($"{ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.OAuthProxyUrl"]}"),
199+
RequestUri = new Uri($"{_appSettings[AppSettingsConstants.UmbracoCmsIntegrationsOAuthProxyUrl]}"),
201200
Content = new FormUrlEncodedContent(data)
202201
};
203202
requestMessage.Headers.Add("service_name", "Hubspot");
@@ -226,14 +225,14 @@ public async Task<string> RefreshAccessToken()
226225
var data = new Dictionary<string, string>
227226
{
228227
{"grant_type", "refresh_token"},
229-
{"client_id", ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.Crm.Hubspot.OAuthClientId"]},
228+
{"client_id", _appSettings[AppSettingsConstants.UmbracoCmsIntegrationsCrmHubspotOAuthClientId] },
230229
{ "refresh_token", refreshToken }
231230
};
232231

233232
var requestMessage = new HttpRequestMessage
234233
{
235234
Method = HttpMethod.Post,
236-
RequestUri = new Uri($"{ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.OAuthProxyUrl"]}"),
235+
RequestUri = new Uri($"{_appSettings[AppSettingsConstants.UmbracoCmsIntegrationsOAuthProxyUrl]}"),
237236
Content = new FormUrlEncodedContent(data)
238237
};
239238
requestMessage.Headers.Add("service_name", "Hubspot");
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
using System.Configuration;
1+
using Umbraco.Cms.Integrations.Crm.Hubspot.Configuration;
22

33
namespace Umbraco.Cms.Integrations.Crm.Hubspot.Services
44
{
55
public class HubspotService: IHubspotService
66
{
7-
private string ClientId => ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.Crm.Hubspot.OAuthClientId"];
7+
private readonly IAppSettings _appSettings;
88

9-
private string RedirectUrl => ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.Crm.Hubspot.OAuthRedirectUrl"];
9+
public HubspotService(IAppSettings appSettings)
10+
{
11+
_appSettings = appSettings;
12+
}
13+
14+
private string ClientId => _appSettings[AppSettingsConstants.UmbracoCmsIntegrationsCrmHubspotOAuthClientId];
15+
16+
private string RedirectUrl =>
17+
_appSettings[AppSettingsConstants.UmbracoCmsIntegrationsCrmHubspotOAuthRedirectUrl];
18+
19+
private string AuthorizationBaseUrl =>
20+
_appSettings[AppSettingsConstants.UmbracoCmsIntegrationsCrmHubspotOAuthAuthorizationBaseUrl];
1021

11-
private string Scopes => ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.Crm.Hubspot.OAuthScopes"];
22+
private string Scopes => _appSettings[AppSettingsConstants.UmbracoCmsIntegrationsCrmHubspotOAuthScopes];
1223

13-
private const string AuthorizationUrlFormat =
14-
"https://app-eu1.hubspot.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}";
24+
private const string AuthorizationUrlFormat = "{0}?client_id={1}&redirect_uri={2}&scope={3}";
1525

1626
public string GetAuthorizationUrl()
1727
{
18-
return string.Format(AuthorizationUrlFormat, ClientId, RedirectUrl, Scopes);
28+
return string.Format(AuthorizationUrlFormat, AuthorizationBaseUrl, ClientId, RedirectUrl, Scopes);
1929
}
2030
}
2131
}

0 commit comments

Comments
 (0)