Skip to content

Commit

Permalink
Merge pull request #48 from CesarD/feat/upgrade_flurlhttp
Browse files Browse the repository at this point in the history
Upgrade Flurl.Http to v4 and Json serialization refactor
  • Loading branch information
sps-campbellwray authored Sep 19, 2024
2 parents 60ed190 + bdd6309 commit d072081
Show file tree
Hide file tree
Showing 244 changed files with 8,278 additions and 6,611 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,4 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/
/test/Keycloak.Net.Tests/appsettings.json
/src/Keycloak.Net/.fossa.yml
/src/Keycloak.Net/.fossa.yml
3 changes: 3 additions & 0 deletions Keycloak.Net.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{A56F65F6
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{04ECC844-41D5-4A2B-85F1-DA1E3B3C58B3}"
ProjectSection(SolutionItems) = preProject
test\insurance-realm-export.json = test\insurance-realm-export.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{46B1B298-8884-4FE7-831D-FBCA62E10A72}"
ProjectSection(SolutionItems) = preProject
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* allow usage of CancellationTokens
* changed ClientConfig to Dictionary<string, string>
* removed signing
* .net 6 support only
* updated for keycloak version 17+
* .NET 8 support only
* updated for keycloak version 25+
* added support for changing default `AdminClientId` which has default `admin-cli` value
* added support for System.Text.Json in replacement of NewtonsoftJson.

To use different AdminClientId, use newly introduced KeyCloakOptions:
```cs
Expand Down Expand Up @@ -60,3 +61,10 @@ See documentation at [https://www.keycloak.org/docs-api/6.0/rest-api/](https://w
* [X] Users
* [X] Root

## Testing

In order to run the tests, all it's needed is to have a running instance of Keycloak with (preferably) the `master` realm credentials admin/admin (as it's currently configured in the `/test/Keycloak.Net.Core.Tests/appsettings.json`) and create a new realm `Insurance` by importing the file in `/test/insurance-real-export.json`, which also has its admin user with the same credentials as mentioned before.

Then it's just as easy as running the tests.

If for some reason you want to change the credentials, you need to make sure both realms have the same user and password as the tests use the same credentials for both `master` and `Insurance` realms.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "6.0.200",
"version": "8.0.401",
"rollForward": "latestFeature"
}
}
57 changes: 28 additions & 29 deletions src/Keycloak.Net.Core/AttackDetection/KeycloakClient.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
using Flurl.Http;
using Keycloak.Net.Models.AttackDetection;
using System.Threading;
using System.Threading.Tasks;
using Keycloak.Net.Models.AttackDetection;

namespace Keycloak.Net
namespace Keycloak.Net;

public partial class KeycloakClient
{
public partial class KeycloakClient
{
public async Task<bool> ClearUserLoginFailuresAsync(string realm, CancellationToken cancellationToken = default)
{
var response = await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/attack-detection/brute-force/users")
.DeleteAsync(cancellationToken)
.ConfigureAwait(false);
return response.ResponseMessage.IsSuccessStatusCode;
}
public async Task<bool> ClearUserLoginFailuresAsync(string realm,
CancellationToken cancellationToken = default)
{
var response = await GetBaseUrl(realm).AppendPathSegment($"/admin/realms/{realm}/attack-detection/brute-force/users")
.DeleteAsync(cancellationToken: cancellationToken)
.ConfigureAwait(false);
return response.ResponseMessage.IsSuccessStatusCode;
}

public async Task<bool> ClearUserLoginFailuresAsync(string realm, string userId, CancellationToken cancellationToken = default)
{
var response = await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/attack-detection/brute-force/users/{userId}")
.DeleteAsync(cancellationToken)
.ConfigureAwait(false);
return response.ResponseMessage.IsSuccessStatusCode;
}
public async Task<bool> ClearUserLoginFailuresAsync(string realm,
string userId,
CancellationToken cancellationToken = default)
{
var response = await GetBaseUrl(realm).AppendPathSegment($"/admin/realms/{realm}/attack-detection/brute-force/users/{userId}")
.DeleteAsync(cancellationToken: cancellationToken)
.ConfigureAwait(false);
return response.ResponseMessage.IsSuccessStatusCode;
}

public async Task<UserNameStatus> GetUserNameStatusInBruteForceDetectionAsync(string realm, string userId, CancellationToken cancellationToken = default) => await GetBaseUrl(realm)
.AppendPathSegment($"/admin/realms/{realm}/attack-detection/brute-force/users/{userId}")
.GetJsonAsync<UserNameStatus>(cancellationToken)
.ConfigureAwait(false);
}
}
public async Task<UserNameStatus> GetUserNameStatusInBruteForceDetectionAsync(string realm,
string userId,
CancellationToken cancellationToken = default) =>
await GetBaseUrl(realm).AppendPathSegment($"/admin/realms/{realm}/attack-detection/brute-force/users/{userId}")
.GetJsonAsync<UserNameStatus>(cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
Loading

0 comments on commit d072081

Please sign in to comment.