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
9 changes: 9 additions & 0 deletions src/OrderCloud.SDK.Tests/SdkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ public void http_error_api_exception_handled() {
Assert.AreEqual(response.HttpStatus, HttpStatusCode.GatewayTimeout);
}


[Test]
public async Task can_get_public_key() {
using (var httpTest = new HttpTest()) {
await GetClient().GetPublicKeyAsync("keyid");
httpTest.ShouldHaveCalled("https://fake.com/oauth/certs/keyid");
}
}

private OrderCloudClient GetClient() => new OrderCloudClient(new OrderCloudClientConfig {
ApiUrl = "https://fake.com",
AuthUrl = "https://fake.com",
Expand Down
16 changes: 16 additions & 0 deletions src/OrderCloud.SDK/OAuthModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,20 @@ public OAuthTokenRequestWithRefreshTokenGrant() {
public string refresh_token { get; set; }
public string client_secret { get; set; }
}

public class PublicKey : OrderCloudModel
{
/// <summary>Kty of the public key.</summary>
public string kty { get => GetProp<string>("kty"); set => SetProp<string>("kty", value); }
/// <summary>N of the public key.</summary>
public string n { get => GetProp<string>("n"); set => SetProp<string>("n", value); }
/// <summary>E of the public key.</summary>
public string e { get => GetProp<string>("e"); set => SetProp<string>("e", value); }
/// <summary>Alg of the public key.</summary>
public string alg { get => GetProp<string>("alg"); set => SetProp<string>("alg", value); }
/// <summary>Use of the public key.</summary>
public string use { get => GetProp<string>("use"); set => SetProp<string>("use", value); }
/// <summary>Kid of the public key.</summary>
public string kid { get => GetProp<string>("kid"); set => SetProp<string>("kid", value); }
}
}
2 changes: 1 addition & 1 deletion 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.4</Version>
<Version>0.18.5</Version>
<PackageId>OrderCloud.SDK</PackageId>
<Title>OrderCloud SDK</Title>
<Authors>Todd Menier</Authors>
Expand Down
11 changes: 11 additions & 0 deletions src/OrderCloud.SDK/OrderCloudClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public partial interface IOrderCloudClient
/// Sends a token request to the OrderCloud authorization server using the OAuth2 refresh_token grant flow.
/// </summary>
Task<TokenResponse> RefreshTokenAsync(string clientID, string refreshToken);

/// <summary>
/// Get a single cert public key. Returns a JSON Web Key (JWK). Can be used for validating the token was signed by OrderCloud.
/// </summary>
Task<PublicKey> GetPublicKeyAsync(string ID, string accessToken = null);
}

public partial class OrderCloudClient : IDisposable
Expand Down Expand Up @@ -153,6 +158,12 @@ public Task<TokenResponse> RefreshTokenAsync(string clientID, string refreshToke
return AuthenticateAsync(req);
}

public async Task<PublicKey> GetPublicKeyAsync(string ID, string accessToken = null) {
return await Request("oauth", "certs", ID)
.WithOAuthBearerToken(accessToken)
.GetJsonAsync<PublicKey>();
}

public void Dispose() => TokenResponse = null;

internal bool EnableModelValidation { get; set; } = true;
Expand Down