Skip to content

Commit

Permalink
Alteração para permitir extender comportamento do httpclient no proce…
Browse files Browse the repository at this point in the history
…sso de interação com o usuário. (#4)
  • Loading branch information
samuelfabel authored Jul 18, 2020
1 parent ae8f4c0 commit 77a29e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Handlers/AuthenticationHeaderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public AuthenticationHeaderHandler(IKeyCloakAuthClient authClient, IOptions<KeyC
private readonly KeyCloakSettings settings;
private readonly IDistributedCache cache;

const string CACHE_KEY = "keycloak_key";
public const string CACHE_KEY = "keycloak_key";

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Expand Down
8 changes: 3 additions & 5 deletions src/RegisterServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ namespace PlusUltra.KeyCloak.ApiClient
{
public static class RegisterServices
{
public static IServiceCollection AddKeyCloakApiClients(this IServiceCollection services, IConfiguration configuration)
public static IHttpClientBuilder AddKeyCloakApiClients(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<KeyCloakSettings>(configuration.GetSection(nameof(KeyCloakSettings)));
var configs = services.BuildServiceProvider().GetRequiredService<IOptions<KeyCloakSettings>>().Value;

services.AddTransient<AuthenticationHeaderHandler>();

services.AddApiClient<IKeyCloakUsersClient>(c => c.BaseAddress = configs.AdminUri)
.AddHttpMessageHandler<AuthenticationHeaderHandler>();

services.AddApiClient<IKeyCloakAuthClient>(c => c.BaseAddress = configs.TokenUri);

return services;
return services.AddApiClient<IKeyCloakUsersClient>(c => c.BaseAddress = configs.AdminUri)
.AddHttpMessageHandler<AuthenticationHeaderHandler>();
}
}
}

0 comments on commit 77a29e8

Please sign in to comment.