Skip to content

Commit

Permalink
Remove redundant formatting
Browse files Browse the repository at this point in the history
Remove redundant string formatting from JumpCloud.
  • Loading branch information
martincostello committed Aug 15, 2023
1 parent 041919a commit 560f5b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* for more information concerning the license and the contributors participating to this project.
*/

using System.Globalization;

namespace AspNet.Security.OAuth.JumpCloud;

/// <summary>
Expand Down Expand Up @@ -36,30 +34,33 @@ public static class JumpCloudAuthenticationDefaults
/// <summary>
/// Default path format to use for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
/// </summary>
[Obsolete("This field is obsolete and will be removed in a future version.")]
public static readonly string AuthorizationEndpointPathFormat = "/oauth2/auth";

/// <summary>
/// Default path format to use for <see cref="OAuthOptions.TokenEndpoint"/>.
/// </summary>
[Obsolete("This field is obsolete and will be removed in a future version.")]
public static readonly string TokenEndpointPathFormat = "/oauth2/token";

/// <summary>
/// Default path format to use for <see cref="OAuthOptions.UserInformationEndpoint"/>.
/// </summary>
[Obsolete("This field is obsolete and will be removed in a future version.")]
public static readonly string UserInformationEndpointPathFormat = "/userinfo";

/// <summary>
/// Default path to use for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
/// </summary>
public static readonly string AuthorizationEndpointPath = string.Format(CultureInfo.InvariantCulture, AuthorizationEndpointPathFormat);
public static readonly string AuthorizationEndpointPath = "/oauth2/auth";

/// <summary>
/// Default path to use for <see cref="OAuthOptions.TokenEndpoint"/>.
/// </summary>
public static readonly string TokenEndpointPath = string.Format(CultureInfo.InvariantCulture, TokenEndpointPathFormat);
public static readonly string TokenEndpointPath = "/oauth2/token";

/// <summary>
/// Default path to use for <see cref="OAuthOptions.UserInformationEndpoint"/>.
/// </summary>
public static readonly string UserInformationEndpointPath = string.Format(CultureInfo.InvariantCulture, UserInformationEndpointPathFormat);
public static readonly string UserInformationEndpointPath = "/userinfo";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* for more information concerning the license and the contributors participating to this project.
*/

using System.Globalization;
using Microsoft.Extensions.Options;

namespace AspNet.Security.OAuth.JumpCloud;
Expand All @@ -24,15 +23,13 @@ public void PostConfigure(
throw new ArgumentException("No JumpCloud domain configured.", nameof(options));
}

options.AuthorizationEndpoint = CreateUrl(options.Domain, JumpCloudAuthenticationDefaults.AuthorizationEndpointPathFormat);
options.TokenEndpoint = CreateUrl(options.Domain, JumpCloudAuthenticationDefaults.TokenEndpointPathFormat);
options.UserInformationEndpoint = CreateUrl(options.Domain, JumpCloudAuthenticationDefaults.UserInformationEndpointPathFormat);
options.AuthorizationEndpoint = CreateUrl(options.Domain, JumpCloudAuthenticationDefaults.AuthorizationEndpointPath);
options.TokenEndpoint = CreateUrl(options.Domain, JumpCloudAuthenticationDefaults.TokenEndpointPath);
options.UserInformationEndpoint = CreateUrl(options.Domain, JumpCloudAuthenticationDefaults.UserInformationEndpointPath);
}

private static string CreateUrl(string domain, string pathFormat, params object[] args)
private static string CreateUrl(string domain, string path)
{
var path = string.Format(CultureInfo.InvariantCulture, pathFormat, args);

// Enforce use of HTTPS
var builder = new UriBuilder(domain)
{
Expand Down

0 comments on commit 560f5b3

Please sign in to comment.