Skip to content

Commit

Permalink
v1.1 - Kiota updates (#1)
Browse files Browse the repository at this point in the history
* Update to Kiota 1.8.0

* Update README

* Update README
  • Loading branch information
Hawxy authored Nov 4, 2023
1 parent f856193 commit c88f47a
Show file tree
Hide file tree
Showing 239 changed files with 689 additions and 503 deletions.
2 changes: 1 addition & 1 deletion Package.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<Authors>Hawxy</Authors>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Clerk API Client for .NET
# Clerk SDK for .NET

[![Nuget](https://img.shields.io/nuget/v/Clerk.Net.DependencyInjection?label=Clerk.Net.DependencyInjection&style=flat-square)](https://www.nuget.org/packages/Clerk.Net.DependencyInjection)
[![Nuget](https://img.shields.io/nuget/v/Clerk.Net?label=Clerk.Net&style=flat-square)](https://www.nuget.org/packages/Clerk.Net)
[![Nuget](https://img.shields.io/nuget/v/Clerk.Net.DependencyInjection?label=Clerk.Net.DependencyInjection&style=flat-square)](https://www.nuget.org/packages/Clerk.Net.DependencyInjection)

_Looking for ASP.NET Core w/ Clerk JWTs? [See below](#what-about-jwt-auth)._

### Packages
**`Clerk.Net`**: Provides the standalone API Client as a Kiota-generated wrapper over Clerk's OpenAPI spec.
Expand Down Expand Up @@ -63,6 +65,49 @@ If you need to configure the underlying `HttpClient` used by the client, you can

For unit testing, see [Unit testing Kiota API clients](https://learn.microsoft.com/en-us/openapi/kiota/testing).

## Disclaimer
### What about JWT Auth?

You might have stumbled upon this repo looking for a solution for validating Clerk JWTs, so I'll include the answer here for completion. Configuring JWT auth for Clerk is a tad _unusual_ as they want you to validate the `azp` parameter instead of specifying an `audience`.
This claim isn't normally validated at the authentication layer, and so you'll need some extra code to get things working:

```cs
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(x =>
{
// Authority is the URL of your clerk instance
x.Authority = builder.Configuration["Clerk:Authority"];
x.TokenValidationParameters = new TokenValidationParameters()
{
// Disable audience validation as we aren't using it
ValidateAudience = false,
NameClaimType = ClaimTypes.NameIdentifier
};
x.Events = new JwtBearerEvents()
{
// Additional validation for AZP claim
OnTokenValidated = context =>
{
var azp = context.Principal?.FindFirstValue("azp");
// AuthorizedParty is the base URL of your frontend.
if (string.IsNullOrEmpty(azp) || !azp.Equals(builder.Configuration["Clerk:AuthorizedParty"]))
context.Fail("AZP Claim is invalid or missing");

return Task.CompletedTask;
}
};
});
```

Your frontend should call Clerk-JS's `getToken` as part of its HTTP middleware and append the token (prefixed with `Bearer`) to the `Authorization` header, for example:
```ts
async onRequestInit({ requestInit }) {
requestInit.headers = {
...requestInit.headers,
Authorization: `Bearer ${await getToken()}`
}
}
```

### Disclaimer

I am not affiliated with nor represent Clerk. All support queries regarding the underlying service should go to [Clerk Support](https://clerk.com/support).
6 changes: 3 additions & 3 deletions src/Clerk.Net.Tests/Clerk.Net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/Clerk.Net/Clerk.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.5.0" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.2.0" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.6.1" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.3.0" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.1.0" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.Kiota.Serialization.Multipart" Version="1.1.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static Actor_tokensPostRequestBody CreateFromDiscriminatorValue(IParseNod
/// <summary>
/// The deserialization information for the current model
/// </summary>
public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
return new Dictionary<string, Action<IParseNode>> {
{"actor", n => { Actor = n.GetObjectValue<Actor_tokensPostRequestBody_actor>(Actor_tokensPostRequestBody_actor.CreateFromDiscriminatorValue); } },
{"expires_in_seconds", n => { ExpiresInSeconds = n.GetIntValue(); } },
Expand All @@ -49,7 +49,7 @@ public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public void Serialize(ISerializationWriter writer) {
public virtual void Serialize(ISerializationWriter writer) {
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteObjectValue<Actor_tokensPostRequestBody_actor>("actor", Actor);
writer.WriteIntValue("expires_in_seconds", ExpiresInSeconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public static Actor_tokensPostRequestBody_actor CreateFromDiscriminatorValue(IPa
/// <summary>
/// The deserialization information for the current model
/// </summary>
public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
return new Dictionary<string, Action<IParseNode>> {
};
}
/// <summary>
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public void Serialize(ISerializationWriter writer) {
public virtual void Serialize(ISerializationWriter writer) {
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteAdditionalData(AdditionalData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ public RequestInformation ToPostRequestInformation(Actor_tokensPostRequestBody b
UrlTemplate = UrlTemplate,
PathParameters = PathParameters,
};
requestInfo.Headers.Add("Accept", "application/json");
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
if (requestConfiguration != null) {
var requestConfig = new RequestConfiguration<DefaultQueryParameters>();
requestConfiguration.Invoke(requestConfig);
requestInfo.AddQueryParameters(requestConfig.QueryParameters);
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers);
}
requestInfo.Headers.TryAdd("Accept", "application/json;q=1");
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
return requestInfo;
}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ public RequestInformation ToPostRequestInformation(Action<RequestConfiguration<D
UrlTemplate = UrlTemplate,
PathParameters = PathParameters,
};
requestInfo.Headers.Add("Accept", "application/json");
if (requestConfiguration != null) {
var requestConfig = new RequestConfiguration<DefaultQueryParameters>();
requestConfiguration.Invoke(requestConfig);
requestInfo.AddQueryParameters(requestConfig.QueryParameters);
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers);
}
requestInfo.Headers.TryAdd("Accept", "application/json;q=1");
return requestInfo;
}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static Allowlist_identifiersPostRequestBody CreateFromDiscriminatorValue(
/// <summary>
/// The deserialization information for the current model
/// </summary>
public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
return new Dictionary<string, Action<IParseNode>> {
{"identifier", n => { Identifier = n.GetStringValue(); } },
{"notify", n => { Notify = n.GetBoolValue(); } },
Expand All @@ -37,7 +37,7 @@ public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public void Serialize(ISerializationWriter writer) {
public virtual void Serialize(ISerializationWriter writer) {
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteStringValue("identifier", Identifier);
writer.WriteBoolValue("notify", Notify);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ public RequestInformation ToGetRequestInformation(Action<RequestConfiguration<De
UrlTemplate = UrlTemplate,
PathParameters = PathParameters,
};
requestInfo.Headers.Add("Accept", "application/json");
if (requestConfiguration != null) {
var requestConfig = new RequestConfiguration<DefaultQueryParameters>();
requestConfiguration.Invoke(requestConfig);
requestInfo.AddQueryParameters(requestConfig.QueryParameters);
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers);
}
requestInfo.Headers.TryAdd("Accept", "application/json;q=1");
return requestInfo;
}
/// <summary>
Expand All @@ -120,14 +121,15 @@ public RequestInformation ToPostRequestInformation(Allowlist_identifiersPostRequ
UrlTemplate = UrlTemplate,
PathParameters = PathParameters,
};
requestInfo.Headers.Add("Accept", "application/json");
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
if (requestConfiguration != null) {
var requestConfig = new RequestConfiguration<DefaultQueryParameters>();
requestConfiguration.Invoke(requestConfig);
requestInfo.AddQueryParameters(requestConfig.QueryParameters);
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers);
}
requestInfo.Headers.TryAdd("Accept", "application/json;q=1");
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
return requestInfo;
}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ public RequestInformation ToDeleteRequestInformation(Action<RequestConfiguration
UrlTemplate = UrlTemplate,
PathParameters = PathParameters,
};
requestInfo.Headers.Add("Accept", "application/json");
if (requestConfiguration != null) {
var requestConfig = new RequestConfiguration<DefaultQueryParameters>();
requestConfiguration.Invoke(requestConfig);
requestInfo.AddQueryParameters(requestConfig.QueryParameters);
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers);
}
requestInfo.Headers.TryAdd("Accept", "application/json;q=1");
return requestInfo;
}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static DomainPutRequestBody CreateFromDiscriminatorValue(IParseNode parse
/// <summary>
/// The deserialization information for the current model
/// </summary>
public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
return new Dictionary<string, Action<IParseNode>> {
{"home_url", n => { HomeUrl = n.GetStringValue(); } },
};
Expand All @@ -34,7 +34,7 @@ public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public void Serialize(ISerializationWriter writer) {
public virtual void Serialize(ISerializationWriter writer) {
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteStringValue("home_url", HomeUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ public RequestInformation ToPutRequestInformation(DomainPutRequestBody body, Act
UrlTemplate = UrlTemplate,
PathParameters = PathParameters,
};
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
if (requestConfiguration != null) {
var requestConfig = new RequestConfiguration<DefaultQueryParameters>();
requestConfiguration.Invoke(requestConfig);
requestInfo.AddQueryParameters(requestConfig.QueryParameters);
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers);
}
requestInfo.Headers.TryAdd("Accept", "application/json, application/json");
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
return requestInfo;
}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Instance_settingsPatchRequestBody CreateFromDiscriminatorValue(IPa
/// <summary>
/// The deserialization information for the current model
/// </summary>
public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
return new Dictionary<string, Action<IParseNode>> {
{"enhanced_email_deliverability", n => { EnhancedEmailDeliverability = n.GetBoolValue(); } },
{"from_email_address", n => { FromEmailAddress = n.GetStringValue(); } },
Expand All @@ -55,7 +55,7 @@ public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public void Serialize(ISerializationWriter writer) {
public virtual void Serialize(ISerializationWriter writer) {
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteBoolValue("enhanced_email_deliverability", EnhancedEmailDeliverability);
writer.WriteStringValue("from_email_address", FromEmailAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static Instance_settingsPatchResponse CreateFromDiscriminatorValue(IParse
/// <summary>
/// The deserialization information for the current model
/// </summary>
public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
return new Dictionary<string, Action<IParseNode>> {
{"enhanced_email_deliverability", n => { EnhancedEmailDeliverability = n.GetBoolValue(); } },
{"from_email_address", n => { FromEmailAddress = n.GetStringValue(); } },
Expand All @@ -63,7 +63,7 @@ public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public void Serialize(ISerializationWriter writer) {
public virtual void Serialize(ISerializationWriter writer) {
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteBoolValue("enhanced_email_deliverability", EnhancedEmailDeliverability);
writer.WriteStringValue("from_email_address", FromEmailAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ public RequestInformation ToPatchRequestInformation(Instance_settingsPatchReques
UrlTemplate = UrlTemplate,
PathParameters = PathParameters,
};
requestInfo.Headers.Add("Accept", "application/json");
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
if (requestConfiguration != null) {
var requestConfig = new RequestConfiguration<DefaultQueryParameters>();
requestConfiguration.Invoke(requestConfig);
requestInfo.AddQueryParameters(requestConfig.QueryParameters);
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers);
}
requestInfo.Headers.TryAdd("Accept", "application/json;q=1");
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
return requestInfo;
}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static Blocklist_identifiersPostRequestBody CreateFromDiscriminatorValue(
/// <summary>
/// The deserialization information for the current model
/// </summary>
public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
return new Dictionary<string, Action<IParseNode>> {
{"identifier", n => { Identifier = n.GetStringValue(); } },
};
Expand All @@ -34,7 +34,7 @@ public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public void Serialize(ISerializationWriter writer) {
public virtual void Serialize(ISerializationWriter writer) {
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteStringValue("identifier", Identifier);
}
Expand Down
Loading

0 comments on commit c88f47a

Please sign in to comment.