diff --git a/README.md b/README.md index 13bf13b..b15e4e1 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ The OrderCloud.io SDK for .NET is a client library for building solutions target ```c# using OrderCloud.SDK; +// authentication relies on an ApiUrl which must be set in OrderCloudClientConfig.cs var client = new OrderCloudClient(new OrderCloudClientConfig { ClientId = "my-client-id", @@ -44,9 +45,9 @@ foreach (var order in orders.Items) { ## Authenticating -OrderCloud.io uses OAuth2 for authentication and authorization. In a nutshell, you provide a set of credentials, acquire a temporary access token, and provide that token in the HTTP headers on subsequent API calls. Using the SDK, you have a few options to simplify this process, depending on the scenario: +OrderCloud.io uses OAuth2 for authentication and authorization. In a nutshell, you provide an ApiUrl, and a set of credentials, acquire a temporary access token, and provide that token in the HTTP headers on subsequent API calls. Using the SDK, you have a few options to simplify this process, depending on the scenario: -1. Configure `OrderCloudClient` with a set of credentials, as in the [example](#example) above. This is ideal for scheduled batch jobs, and you should prefer the client credentials grant (shared secret) flow since this processing isn't usually triggered by or on behalf of a particular user. With this method, you don't need to explicitly authenticate or keep track of access tokens - the SDK will acquire, cache, and refresh tokens implicitly as needed. Just configure the client and start making calls. (And please, please, _PLEASE_ keep shared secrets and user credentials securly locked down, such as with [Azure Key Vault](https://azure.microsoft.com/en-us/services/key-vault/).) +1. Configure `OrderCloudClient` with a set of credentials, as in the [example](#example) above. This is ideal for any processes happening outside of your user experience layer, since this processing isn't usually triggered by or on behalf of a particular user. With this method, you don't need to explicitly authenticate or keep track of access tokens - the SDK will acquire, cache, and refresh tokens implicitly as needed. Just configure the client and start making calls. (And please, please, _PLEASE_ keep shared secrets and user credentials securly locked down, such as with [Azure Key Vault](https://azure.microsoft.com/en-us/services/key-vault/).) 2. Use an existing access token. A typical use case is when a user has already authenticated with OrderCloud in a front-end app and you want some custom endpoint to perform actions on behalf of that user. _Do not pass the user's credentials to your custom endpoint_. Instead, pass their token (always over SSL). Every method in the SDK that calls an OrderCloud endpoint takes an optional `accessToken` argument, allowing you to ignore any configured credentials and use the ad-hoc token: diff --git a/src/OrderCloud.SDK.Tests/OrderCloud.SDK.Tests.csproj b/src/OrderCloud.SDK.Tests/OrderCloud.SDK.Tests.csproj index e7bff20..0fb8290 100644 --- a/src/OrderCloud.SDK.Tests/OrderCloud.SDK.Tests.csproj +++ b/src/OrderCloud.SDK.Tests/OrderCloud.SDK.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net10.0 @@ -15,9 +15,9 @@ - - - + + + diff --git a/src/OrderCloud.SDK.Tests/SdkTests.cs b/src/OrderCloud.SDK.Tests/SdkTests.cs index 072a1fd..4e108b6 100644 --- a/src/OrderCloud.SDK.Tests/SdkTests.cs +++ b/src/OrderCloud.SDK.Tests/SdkTests.cs @@ -113,8 +113,7 @@ public void can_serialize_partial() { public async Task can_provide_alternative_token() { // prove that auth credentials are no longer required like in earlier versions var cli = new OrderCloudClient(new OrderCloudClientConfig { - ApiUrl = "https://fake.com", - AuthUrl = "https://fake.com" + ApiUrl = "https://fake.com" }); using (var httpTest = new HttpTest()) { @@ -127,7 +126,6 @@ public async Task can_provide_alternative_token() { public async Task missing_bearer_token_obtains_new_token() { var cli = new OrderCloudClient(new OrderCloudClientConfig { ApiUrl = "https://fake.com", - AuthUrl = "https://fake.com", ClientId = "client-id", ClientSecret = "client-secret", }); @@ -339,7 +337,6 @@ public async Task can_get_public_key() { private OrderCloudClient GetClient() => new OrderCloudClient(new OrderCloudClientConfig { ApiUrl = "https://fake.com", - AuthUrl = "https://fake.com", ClientId = "xyz", Username = "u", Password = "p" diff --git a/src/OrderCloud.SDK/Generated/ErrorCodes.cs b/src/OrderCloud.SDK/Generated/ErrorCodes.cs index 507f5aa..a5078af 100644 --- a/src/OrderCloud.SDK/Generated/ErrorCodes.cs +++ b/src/OrderCloud.SDK/Generated/ErrorCodes.cs @@ -352,13 +352,6 @@ public static class Locale /// You are allowed only a single language/currency combination per marketplace. public const string DuplicateLanguageAndCurrency = "Locale.DuplicateLanguageAndCurrency"; } - public static class MessageSenders - { - /// Url is required when no delivery configuration is specified. - public const string UrlRequired = "MessageSenders.UrlRequired"; - /// SharedKey is required when no delivery configuration is specified. - public const string SharedKeyRequired = "MessageSenders.SharedKeyRequired"; - } public static class OneTimePasswordRequest { /// Username or email is required. diff --git a/src/OrderCloud.SDK/Generated/Models.cs b/src/OrderCloud.SDK/Generated/Models.cs index 15e3a74..eafefe0 100644 --- a/src/OrderCloud.SDK/Generated/Models.cs +++ b/src/OrderCloud.SDK/Generated/Models.cs @@ -802,8 +802,8 @@ public class DeliveryTargets : OrderCloudModel public AzureTableConfig AzureTable { get => GetProp("AzureTable"); set => SetProp("AzureTable", value); } /// Cosmos db of the delivery target. public CosmosDbConfig CosmosDb { get => GetProp("CosmosDb"); set => SetProp("CosmosDb", value); } - /// Mandrill of the delivery target. - public MandrillConfig Mandrill { get => GetProp("Mandrill"); set => SetProp("Mandrill", value); } + /// Mailchimp of the delivery target. + public MailchimpConfig Mailchimp { get => GetProp("Mailchimp"); set => SetProp("Mailchimp", value); } /// Message sender of the delivery target. public MessageSenderConfig MessageSender { get => GetProp("MessageSender"); set => SetProp("MessageSender", value); } /// Content hub of the delivery target. @@ -1562,10 +1562,9 @@ public class LocaleAssignment : OrderCloudModel /// ID of the user group. Sortable: priority level 3. public string UserGroupID { get => GetProp("UserGroupID"); set => SetProp("UserGroupID", value); } } - public class MandrillConfig : OrderCloudModel + public class MailchimpConfig : OrderCloudModel { - /// Api key of the mandrill config. Required. Max length 50 characters. - [Required] + /// The Mailchimp API key. If this property is not set, the default OrderCloud Mailchimp instance is used. The default instance is intended for test purposes only. [ApiWriteOnly] public string ApiKey { get => GetProp("ApiKey"); set => SetProp("ApiKey", value); } } @@ -1619,15 +1618,12 @@ public class MessageSender : OrderCloudModel public IList MessageTypes { get => GetProp>("MessageTypes", new List()); set => SetProp>("MessageTypes", value); } /// Description of the message sender. public string Description { get => GetProp("Description"); set => SetProp("Description", value); } - /// URL the message sender will POST data to, likely a route within your middleware. - public string URL { get => GetProp("URL"); set => SetProp("URL", value); } /// If additional data not provided by the message sender is needed, provide any elevated roles needed to make additional calls. public IList ElevatedRoles { get => GetProp>("ElevatedRoles", new List()); set => SetProp>("ElevatedRoles", value); } - /// Security feature that allows your middleware to verify the digital signature in the request header to ensure you only accept trusted data. - public string SharedKey { get => GetProp("SharedKey"); set => SetProp("SharedKey", value); } /// Container for extended (custom) properties of the message sender. public dynamic xp { get => GetProp("xp", new ExpandoObject()); set => SetProp("xp", value); } - /// ID of the delivery config. + /// ID of the delivery config. Required. + [Required] public string DeliveryConfigID { get => GetProp("DeliveryConfigID"); set => SetProp("DeliveryConfigID", value); } /// Allow message sender to trigger for all buyers without creating explicit assignments. public bool AllowAllBuyers { get => GetProp("AllowAllBuyers", false); set => SetProp("AllowAllBuyers", value); } @@ -1757,7 +1753,7 @@ public class OpenIdConnect : OrderCloudModel /// A secret string from the Identity Provider that grants access to get JWT tokens. [Required] public string ConnectClientSecret { get => GetProp("ConnectClientSecret"); set => SetProp("ConnectClientSecret", value); } - /// A URL on your front-end ordering site where users will be redirected after they authenticate through the Identity Provider. The string "{token}" will be replaced with a valid OrderCloud JWT. + /// A URL on your front-end ordering site where users will be redirected after they authenticate through the Identity Provider. Supports placeholders: {0} = OrderCloud access token, {1} = IdP access token, {2} = appStartPath, {3} = OrderCloud refresh token, {4} = IdP refresh token (if available). [Required] public string AppStartUrl { get => GetProp("AppStartUrl"); set => SetProp("AppStartUrl", value); } /// A publicly known URL from the Identity Provider that redirects to a resource where users enter personal credentials. @@ -3428,13 +3424,13 @@ public class Subscription : OrderCloudModel /// Next order date of the subscription. The hourly process that creates subscription orders will query for subscriptions with a NextOrderDate between now and five hours ago. [Required] public DateTimeOffset? NextOrderDate { get => GetProp("NextOrderDate"); set => SetProp("NextOrderDate", value); } - /// Last order date of the subscription. Sortable: priority level 2. + /// Last order date of the subscription. Sortable. [ApiReadOnly] public DateTimeOffset? LastOrderDate { get => GetProp("LastOrderDate"); set => SetProp("LastOrderDate", value); } /// Date that subscription order reminder message sender will be triggered if used. Value is the result of NextOrderDate less NotificationDays on the subscription integration. [ApiReadOnly] public DateTimeOffset? NotificationDate { get => GetProp("NotificationDate"); set => SetProp("NotificationDate", value); } - /// Date created of the subscription. Sortable: priority level 3. + /// Date created of the subscription. Sortable. [ApiReadOnly] public DateTimeOffset? DateCreated { get => GetProp("DateCreated"); set => SetProp("DateCreated", value); } /// End date of the subscription. Sortable. @@ -3937,7 +3933,7 @@ public class PartialLineItemVariant : LineItemVariant, IPartial { } public class PartialLineItemVariant : PartialLineItemVariant { } public class PartialLocale : Locale, IPartial { } - public class PartialMandrillConfig : MandrillConfig, IPartial { } + public class PartialMailchimpConfig : MailchimpConfig, IPartial { } public class PartialMeBuyer : MeBuyer, IPartial { } public class PartialMeSeller : MeSeller, IPartial { } public class PartialMessageSender : MessageSender, IPartial { } diff --git a/src/OrderCloud.SDK/OrderCloud.SDK.csproj b/src/OrderCloud.SDK/OrderCloud.SDK.csproj index 8546df5..3cace95 100644 --- a/src/OrderCloud.SDK/OrderCloud.SDK.csproj +++ b/src/OrderCloud.SDK/OrderCloud.SDK.csproj @@ -4,7 +4,7 @@ netstandard2.0;net461 True - 0.18.13 + 0.19.00 OrderCloud.SDK OrderCloud SDK Todd Menier @@ -30,7 +30,7 @@ - + diff --git a/src/OrderCloud.SDK/OrderCloudClient.cs b/src/OrderCloud.SDK/OrderCloudClient.cs index 6f90e00..19a859f 100644 --- a/src/OrderCloud.SDK/OrderCloudClient.cs +++ b/src/OrderCloud.SDK/OrderCloudClient.cs @@ -88,7 +88,7 @@ public partial class OrderCloudClient : IDisposable }); protected virtual IFlurlClient ApiClient => _clientFac.Get(Config.ApiUrl); - protected virtual IFlurlClient AuthClient => _clientFac.Get(Config.AuthUrl); + protected virtual IFlurlClient AuthClient => _clientFac.Get(Config.ApiUrl); public OrderCloudClient() : this(new OrderCloudClientConfig()) { } diff --git a/src/OrderCloud.SDK/OrderCloudClientConfig.cs b/src/OrderCloud.SDK/OrderCloudClientConfig.cs index 3ecd15e..223f3d3 100644 --- a/src/OrderCloud.SDK/OrderCloudClientConfig.cs +++ b/src/OrderCloud.SDK/OrderCloudClientConfig.cs @@ -32,14 +32,10 @@ public class OrderCloudClientConfig /// public GrantType GrantType { get; set; } /// - /// The root URL of the OrderCloud API. You should not need to change this from the default. + /// The base URL of the OrderCloud API you're targeting. This URL can be found on your dashboard or in the upper right hand context menu of your OrderCloud application in Sitecore Portal. /// public string ApiUrl { get; set; } = "https://api.ordercloud.io"; /// - /// The root URL of the OrderCloud authorization server. You should not need to change this from the default. - /// - public string AuthUrl { get; set; } = "https://auth.ordercloud.io"; - /// /// The OAuth2 client ID. Always required. /// public string ClientId { get; set; }