Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
elsand authored Oct 25, 2022
1 parent e396052 commit 65fecb2
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Here is an example with a both a [named](https://docs.microsoft.com/en-us/aspnet
```c#
// Named client
services.AddMaskinportenHttpClient<SettingsJwkClientDefinition>("myhttpclient",
Configuration.GetSection("MaskinportenSettings"));
Configuration.GetSection("MaskinportenSettings"));

// Typed client (MyMaskinportenHttpClient is any class accepting a HttpClient paramter in its constructor)
services.AddMaskinportenHttpClient<SettingsJwkClientDefinition, MyMaskinportenHttpClient>(
Configuration.GetSection("MaskinportenSettings"));
Configuration.GetSection("MaskinportenSettings"));

// Another typed client, using the same app settings, but overriding the setting for Altinn token exchange
services.AddMaskinportenHttpClient<SettingsJwkClientDefinition, MyMaskinportenHttpClient>(
Expand All @@ -36,6 +36,22 @@ services.AddMaskinportenHttpClient<SettingsJwkClientDefinition, MyMaskinportenHt
clientDefinition.ClientSettings.ExhangeToAltinnToken = true;
});

// You can chain additional handlers or configure the client if required
services.AddMaskinportenHttpClient<SettingsJwkClientDefinition, MyMaskinportenHttpClient>(
Configuration.GetSection("MaskinportenSettings))
.AddHttpMessageHandler(sp => ...)
.ConfigureHttpClient(client => ...)

// Registering av Maskinporten-powered client without adding it to HttpClientFactory / DIC
services.RegisterMaskinportenHttpClient<SettingsJwkClientDefinition, MyMaskinportenHttpClient>(
Configuration.GetSection("MaskinportenSettingsForSomeExternalApi"));

// This can then be added as a HttpMessageHandler to any IClientBuilder. This is
// useful if you're already using a client builder (DAN, Polly, Refit etc).
services.AddHttpClient<MyMaskinportenHttpClient>()
.AddMaskinportenHttpMessageHandler<SettingsJwkClientDefinition, MyMaskinportenHttpClient>();


```
2. Configure Maskinporten environment in appsetting.json

Expand Down Expand Up @@ -274,4 +290,4 @@ When facing issues, you might want to temporarily enable debug logging in the se
```

This will cause various information to be logged with severity "Information" to the injected logger. All log entries will have the prefix `[Altinn.ApiClients.Maskinporten DEBUG]: `.
> Warning! This will cause signed assertions (a short-lived secret) to be logged, so only use this in troubleshooting scenarios. No private key material will be logged.
> Warning! This will cause signed assertions (a short-lived secret) to be logged, so only use this in troubleshooting scenarios. No private key material will be logged.

0 comments on commit 65fecb2

Please sign in to comment.