Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand All @@ -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:

Expand Down
8 changes: 4 additions & 4 deletions src/OrderCloud.SDK.Tests/OrderCloud.SDK.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp3.1|AnyCPU'">
Expand All @@ -15,9 +15,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 1 addition & 4 deletions src/OrderCloud.SDK.Tests/SdkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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",
});
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 0 additions & 7 deletions src/OrderCloud.SDK/Generated/ErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,6 @@ public static class Locale
/// <summary>You are allowed only a single language/currency combination per marketplace.</summary>
public const string DuplicateLanguageAndCurrency = "Locale.DuplicateLanguageAndCurrency";
}
public static class MessageSenders
{
/// <summary>Url is required when no delivery configuration is specified.</summary>
public const string UrlRequired = "MessageSenders.UrlRequired";
/// <summary>SharedKey is required when no delivery configuration is specified.</summary>
public const string SharedKeyRequired = "MessageSenders.SharedKeyRequired";
}
public static class OneTimePasswordRequest
{
/// <summary>Username or email is required.</summary>
Expand Down
24 changes: 10 additions & 14 deletions src/OrderCloud.SDK/Generated/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,8 @@ public class DeliveryTargets : OrderCloudModel
public AzureTableConfig AzureTable { get => GetProp<AzureTableConfig>("AzureTable"); set => SetProp<AzureTableConfig>("AzureTable", value); }
/// <summary>Cosmos db of the delivery target.</summary>
public CosmosDbConfig CosmosDb { get => GetProp<CosmosDbConfig>("CosmosDb"); set => SetProp<CosmosDbConfig>("CosmosDb", value); }
/// <summary>Mandrill of the delivery target.</summary>
public MandrillConfig Mandrill { get => GetProp<MandrillConfig>("Mandrill"); set => SetProp<MandrillConfig>("Mandrill", value); }
/// <summary>Mailchimp of the delivery target.</summary>
public MailchimpConfig Mailchimp { get => GetProp<MailchimpConfig>("Mailchimp"); set => SetProp<MailchimpConfig>("Mailchimp", value); }
/// <summary>Message sender of the delivery target.</summary>
public MessageSenderConfig MessageSender { get => GetProp<MessageSenderConfig>("MessageSender"); set => SetProp<MessageSenderConfig>("MessageSender", value); }
/// <summary>Content hub of the delivery target.</summary>
Expand Down Expand Up @@ -1562,10 +1562,9 @@ public class LocaleAssignment : OrderCloudModel
/// <summary>ID of the user group. Sortable: priority level 3.</summary>
public string UserGroupID { get => GetProp<string>("UserGroupID"); set => SetProp<string>("UserGroupID", value); }
}
public class MandrillConfig : OrderCloudModel
public class MailchimpConfig : OrderCloudModel
{
/// <summary>Api key of the mandrill config. Required. Max length 50 characters.</summary>
[Required]
/// <summary>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.</summary>
[ApiWriteOnly]
public string ApiKey { get => GetProp<string>("ApiKey"); set => SetProp<string>("ApiKey", value); }
}
Expand Down Expand Up @@ -1619,15 +1618,12 @@ public class MessageSender : OrderCloudModel
public IList<MessageType> MessageTypes { get => GetProp<IList<MessageType>>("MessageTypes", new List<MessageType>()); set => SetProp<IList<MessageType>>("MessageTypes", value); }
/// <summary>Description of the message sender.</summary>
public string Description { get => GetProp<string>("Description"); set => SetProp<string>("Description", value); }
/// <summary>URL the message sender will POST data to, likely a route within your middleware.</summary>
public string URL { get => GetProp<string>("URL"); set => SetProp<string>("URL", value); }
/// <summary>If additional data not provided by the message sender is needed, provide any elevated roles needed to make additional calls.</summary>
public IList<ApiRole> ElevatedRoles { get => GetProp<IList<ApiRole>>("ElevatedRoles", new List<ApiRole>()); set => SetProp<IList<ApiRole>>("ElevatedRoles", value); }
/// <summary>Security feature that allows your middleware to verify the digital signature in the request header to ensure you only accept trusted data.</summary>
public string SharedKey { get => GetProp<string>("SharedKey"); set => SetProp<string>("SharedKey", value); }
/// <summary>Container for extended (custom) properties of the message sender.</summary>
public dynamic xp { get => GetProp<dynamic>("xp", new ExpandoObject()); set => SetProp<dynamic>("xp", value); }
/// <summary>ID of the delivery config.</summary>
/// <summary>ID of the delivery config. Required.</summary>
[Required]
public string DeliveryConfigID { get => GetProp<string>("DeliveryConfigID"); set => SetProp<string>("DeliveryConfigID", value); }
/// <summary>Allow message sender to trigger for all buyers without creating explicit assignments.</summary>
public bool AllowAllBuyers { get => GetProp<bool>("AllowAllBuyers", false); set => SetProp<bool>("AllowAllBuyers", value); }
Expand Down Expand Up @@ -1757,7 +1753,7 @@ public class OpenIdConnect : OrderCloudModel
/// <summary>A secret string from the Identity Provider that grants access to get JWT tokens.</summary>
[Required]
public string ConnectClientSecret { get => GetProp<string>("ConnectClientSecret"); set => SetProp<string>("ConnectClientSecret", value); }
/// <summary>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.</summary>
/// <summary>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).</summary>
[Required]
public string AppStartUrl { get => GetProp<string>("AppStartUrl"); set => SetProp<string>("AppStartUrl", value); }
/// <summary>A publicly known URL from the Identity Provider that redirects to a resource where users enter personal credentials.</summary>
Expand Down Expand Up @@ -3428,13 +3424,13 @@ public class Subscription : OrderCloudModel
/// <summary>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.</summary>
[Required]
public DateTimeOffset? NextOrderDate { get => GetProp<DateTimeOffset?>("NextOrderDate"); set => SetProp<DateTimeOffset?>("NextOrderDate", value); }
/// <summary>Last order date of the subscription. Sortable: priority level 2.</summary>
/// <summary>Last order date of the subscription. Sortable.</summary>
[ApiReadOnly]
public DateTimeOffset? LastOrderDate { get => GetProp<DateTimeOffset?>("LastOrderDate"); set => SetProp<DateTimeOffset?>("LastOrderDate", value); }
/// <summary>Date that subscription order reminder message sender will be triggered if used. Value is the result of NextOrderDate less NotificationDays on the subscription integration.</summary>
[ApiReadOnly]
public DateTimeOffset? NotificationDate { get => GetProp<DateTimeOffset?>("NotificationDate"); set => SetProp<DateTimeOffset?>("NotificationDate", value); }
/// <summary>Date created of the subscription. Sortable: priority level 3.</summary>
/// <summary>Date created of the subscription. Sortable.</summary>
[ApiReadOnly]
public DateTimeOffset? DateCreated { get => GetProp<DateTimeOffset?>("DateCreated"); set => SetProp<DateTimeOffset?>("DateCreated", value); }
/// <summary>End date of the subscription. Sortable.</summary>
Expand Down Expand Up @@ -3937,7 +3933,7 @@ public class PartialLineItemVariant : LineItemVariant, IPartial { }
public class PartialLineItemVariant<Txp> : 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 { }
Expand Down
4 changes: 2 additions & 2 deletions src/OrderCloud.SDK/OrderCloud.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- https://docs.microsoft.com/en-us/dotnet/core/tools/csproj -->
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>0.18.13</Version>
<Version>0.19.00</Version>
<PackageId>OrderCloud.SDK</PackageId>
<Title>OrderCloud SDK</Title>
<Authors>Todd Menier</Authors>
Expand All @@ -30,7 +30,7 @@
<ItemGroup>
<PackageReference Include="Flurl.Http" Version="3.2.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<None Include="..\..\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/OrderCloud.SDK/OrderCloudClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) { }

Expand Down
6 changes: 1 addition & 5 deletions src/OrderCloud.SDK/OrderCloudClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ public class OrderCloudClientConfig
/// </summary>
public GrantType GrantType { get; set; }
/// <summary>
/// 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.
/// </summary>
public string ApiUrl { get; set; } = "https://api.ordercloud.io";
/// <summary>
/// The root URL of the OrderCloud authorization server. You should not need to change this from the default.
/// </summary>
public string AuthUrl { get; set; } = "https://auth.ordercloud.io";
/// <summary>
/// The OAuth2 client ID. Always required.
/// </summary>
public string ClientId { get; set; }
Expand Down
Loading