Skip to content

Commit 2ca518a

Browse files
committed
Group services and update settings
1 parent e0be609 commit 2ca518a

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/Umbraco.Cms.Integrations.OAuthProxy/Configuration/AppSettings.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
{
33
public class AppSettings
44
{
5-
public string HubspotAuthUri { get; set; }
6-
75
public string HubspotClientSecret { get; set; }
86

9-
public string SemrushAuthUri { get; set; }
10-
117
public string SemrushClientSecret { get; set; }
128

139
public string this[string propertyName] => (string) GetType().GetProperty(propertyName)?.GetValue(this, null);

src/Umbraco.Cms.Integrations.OAuthProxy/Controllers/OAuthProxyController.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ public class OAuthProxyController : Controller
2020

2121
public const string ServiceNameHeaderKey = "service_name";
2222

23-
private static List<string> ValidServiceNames = new List<string> {"Hubspot", "Semrush"};
23+
/// <summary>
24+
/// Integrated services with their token URIs
25+
/// </summary>
26+
private static Dictionary<string, string> ValidServices = new Dictionary<string, string>
27+
{
28+
{ "Hubspot", "oauth/v1/token" }, { "Semrush", "oauth2/access_token" }
29+
};
30+
31+
//private static List<string> ValidServiceNames = new List<string> {"Hubspot", "Semrush"};
2432

2533
public OAuthProxyController(IHttpClientFactory httpClientFactory, IOptions<AppSettings> appSettings)
2634
{
@@ -37,7 +45,7 @@ public async Task ProxyTokenRequest()
3745
serviceName = "Hubspot";
3846
}
3947

40-
if (!ValidServiceNames.Contains(serviceName))
48+
if (!ValidServices.ContainsKey(serviceName))
4149
{
4250
throw
4351
new InvalidOperationException($"Provided {ServiceNameHeaderKey} header value of {serviceName} is not supported");
@@ -46,7 +54,7 @@ public async Task ProxyTokenRequest()
4654
var httpClient = _httpClientFactory.CreateClient($"{serviceName}Token");
4755

4856
var response =
49-
await httpClient.PostAsync(GetAuthUri(serviceName), GetContent(Request.Form, serviceName));
57+
await httpClient.PostAsync(ValidServices[serviceName], GetContent(Request.Form, serviceName));
5058
var content = await response.Content.ReadAsStringAsync();
5159

5260
Response.StatusCode = (int)response.StatusCode;
@@ -65,7 +73,5 @@ private HttpContent GetContent(IFormCollection form, string serviceName)
6573
}
6674

6775
private string GetClientSecret(string serviceName) => _appSettings[$"{serviceName}ClientSecret"];
68-
69-
private string GetAuthUri(string serviceName) => _appSettings[$"{serviceName}AuthUri"];
7076
}
7177
}

src/Umbraco.Cms.Integrations.OAuthProxy/appsettings.Development.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
}
99
},
1010
"AppSettings": {
11-
"HubspotAuthUri": "",
1211
"HubspotClientSecret": "",
13-
"SemrushAuthUri": "oauth2/access_token",
14-
"SemrushClientSecret": "XOPzh6WKjOI5bfhB0M26dIWFHLfktOWk"
12+
"SemrushClientSecret": ""
1513
}
1614
}

0 commit comments

Comments
 (0)