Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Ory.Kratos.Client to LeanCode.Kratos.Client #681

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

Saancreed
Copy link
Member

@Saancreed Saancreed commented Jul 11, 2024

This won't build successfully until we actually push the package but works on my machine™.

The registration and usage changed a bit but it's still the closest we have to old Newtonsoft-based client.


if (session is null)
{
return AuthenticateResult.NoResult();
}
else if (!session.Active)
else if (session.Active != true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you're wondering, this is nullable now.

{
if (Request.Headers.TryGetValue("X-Session-Token", out var token) && !string.IsNullOrEmpty(token))
{
return api.ToSessionAsync(xSessionToken: token);
return await api.ToSessionAsync(xSessionToken: token.ToString());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, this was a simple string parameter so implicit conversion from StringValues worked. Now it's Option<string> so it's not so easy anymore.

@@ -76,49 +76,49 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
}
}

protected virtual Task<KratosSession?> GetSessionAsync()
protected virtual async Task<IToSessionApiResponse?> GetSessionAsync()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated result type is now an interface that also exposes some additional info about whether the call succeeded or not.

new("exp", ToUnixTimeSecondsString(session.ExpiresAt)),
new("auth_time", ToUnixTimeSecondsString(session.AuthenticatedAt)),
new(Options.NameClaimType, session.Identity!.Id),
new("iss", SchemaUrlPathRegex().Replace(session.Identity.SchemaUrl, string.Empty)),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're now chopping off the schema URL path from the response, which should result in the base URL under which Kratos is publically accessible.

@@ -191,14 +227,15 @@ public async Task Maps_session_and_identity_properties_to_principals_claims()
c.Add(new(o.RoleClaimType, "developer"));
}

if (s.Identity.MetadataPublic is MetadataPublic { IsAdmin: true })
if (s.Identity.MetadataPublic is Option<object> { Value: MetadataPublic { IsAdmin: true } })
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite disgusting, we now have to match against the Option<object> intermediate thingy.

@Saancreed Saancreed marked this pull request as ready for review July 16, 2024 13:33
Copy link
Contributor

@Dragemil Dragemil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine, doesn't seem like an improvement from this side, but maybe the generated client itself will be more convenient for server app usage.

Copy link

github-actions bot commented Jul 16, 2024

Test Results

 35 files  ±0  136 suites  ±0   1m 7s ⏱️ -3s
772 tests ±0  759 ✅ ±0  13 💤 ±0  0 ❌ ±0 
788 runs  ±0  768 ✅ ±0  20 💤 ±0  0 ❌ ±0 

Results for commit 21077ea. ± Comparison against base commit efe1735.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 65.61%. Comparing base (9bd9743) to head (e205adb).
Report is 5 commits behind head on v8.1-preview.

Files Patch % Lines
...ure/LeanCode.Kratos/KratosAuthenticationHandler.cs 85.71% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           v8.1-preview     #681      +/-   ##
================================================
+ Coverage         65.56%   65.61%   +0.04%     
================================================
  Files               263      263              
  Lines              6032     5991      -41     
  Branches            380      377       -3     
================================================
- Hits               3955     3931      -24     
+ Misses             1967     1948      -19     
- Partials            110      112       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Saancreed Saancreed merged commit 0ed633f into v8.1-preview Jul 17, 2024
8 checks passed
@Saancreed Saancreed deleted the leancode-kratos-client branch July 17, 2024 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants