Skip to content

Commit

Permalink
Refactor string concatenation method
Browse files Browse the repository at this point in the history
Changed the method of concatenating strings from Path.Combine() to string interpolation for creating URLs in the Kinde authentication system. Now, the "Domain" configuration is also being trimmed at the end to ensure a clean and proper URL is created using string interpolation.
  • Loading branch information
JonathanVil committed May 31, 2024
1 parent a4b3086 commit 2ad4672
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions KindeAuthenticationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public static AuthenticationBuilder AddKindeJwtBearerAuthentication(this IServic
kindeAuthenticationOptions(configOptions);

if (string.IsNullOrEmpty(configOptions.Domain))
configOptions.Domain = GetRequiredConfiguration("Kinde:Domain", configuration);
configOptions.Domain = GetRequiredConfiguration("Kinde:Domain", configuration).TrimEnd('/');
if (string.IsNullOrEmpty(configOptions.ClientId))
configOptions.ClientId = GetRequiredConfiguration("Kinde:ClientId", configuration);
if (string.IsNullOrEmpty(configOptions.ClientSecret))
configOptions.ClientSecret = GetRequiredConfiguration("Kinde:ClientSecret", configuration);
if (string.IsNullOrEmpty(configOptions.ManagementApiAudience))
configOptions.ManagementApiAudience = Path.Combine(configOptions.Domain, "api");
configOptions.ManagementApiAudience = $"{configOptions.Domain}/api";
if (string.IsNullOrEmpty(configOptions.JwtAudience))
configOptions.JwtAudience = GetRequiredConfiguration("Kinde:JwtAudience", configuration);

Expand All @@ -65,7 +65,7 @@ public static AuthenticationBuilder AddKindeJwtBearerAuthentication(this IServic
{
var client = new HttpClient();
// TODO: cache this?
var response = client.GetAsync(new Uri(Path.Combine(configOptions.Domain, ".well-known/jwks"))).Result;
var response = client.GetAsync(new Uri($"{configOptions.Domain}/.well-known/jwks")).Result;
var responseString = response.Content.ReadAsStringAsync().Result;
return JwksHelper.LoadKeysFromJson(responseString);
}
Expand Down Expand Up @@ -205,15 +205,15 @@ public static AuthenticationBuilder AddKindeIdentityAuthentication(this IService
kindeAuthenticationOptions(configOptions);

if (string.IsNullOrEmpty(configOptions.Domain))
configOptions.Domain = GetRequiredConfiguration("Kinde:Domain", configuration);
configOptions.Domain = GetRequiredConfiguration("Kinde:Domain", configuration).TrimEnd('/');
if (string.IsNullOrEmpty(configOptions.ClientId))
configOptions.ClientId = GetRequiredConfiguration("Kinde:ClientId", configuration);
if (string.IsNullOrEmpty(configOptions.ClientSecret))
configOptions.ClientSecret = GetRequiredConfiguration("Kinde:ClientSecret", configuration);
if (string.IsNullOrEmpty(configOptions.SignedOutRedirectUri))
configOptions.SignedOutRedirectUri = GetRequiredConfiguration("Kinde:SignedOutRedirectUri", configuration);
if (string.IsNullOrEmpty(configOptions.ManagementApiAudience))
configOptions.ManagementApiAudience = Path.Combine(configOptions.Domain, "api");
configOptions.ManagementApiAudience = $"{configOptions.Domain}/api";

services.AddHttpClient();
services.AddHttpContextAccessor();
Expand Down
2 changes: 1 addition & 1 deletion ManagementApi/KindeManagementApiAuthenticationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<string> GetAuthTokenAsync()
content.Headers.Clear();
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

var response = await client.PostAsync(Path.Combine(options.Domain, "oauth2/token"), content).ConfigureAwait(false);
var response = await client.PostAsync($"{options.Domain}/oauth2/token", content).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
logger.LogCritical(@"Unable to authenticate with Kinde Management API {StatusCode} {Error}",
Expand Down

0 comments on commit 2ad4672

Please sign in to comment.