Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f0e4720
Add JWT/mTLS authentication
fredrbus Jul 9, 2026
dfc261d
Rewrite RequestContentHashFilter as interceptor
fredrbus Jul 9, 2026
434a38d
Set "request-path" attrubute in own interceptor
fredrbus Jul 9, 2026
9c2f5fa
Make authentication method explicit
fredrbus Jul 24, 2026
fdfe128
Add docs for v19
fredrbus Jul 24, 2026
3b14532
Redirect docs root only to current version
fredrbus Jul 27, 2026
fb68e81
Fix scope structure
fredrbus Jul 28, 2026
422a7a3
Derive OAuth resource from DigipostClientConfig
fredrbus Aug 14, 2026
ee5943f
Align examples in docs with recent changes
fredrbus Aug 14, 2026
e927701
Fail fast when signing unhashed content
fredrbus Aug 14, 2026
ae66117
DigipostClientException when token retrieval fails
fredrbus Aug 14, 2026
df1ebe2
Clamp token cache to a positive duration
fredrbus Aug 14, 2026
1dca8eb
Test MutualTlsTokenProvider with local endpoint
fredrbus Aug 21, 2026
1c76ba7
Replace AuthMode with two factory methods
fredrbus Aug 21, 2026
8eb7e8f
Log interceptor events under one logger
fredrbus Aug 21, 2026
380c916
Decouple RequestBearerTokenInterceptor from the token provider
fredrbus Aug 21, 2026
1da5598
Req.HttpReq.PathInterceptor to Req.PathInterceptor
fredrbus Aug 21, 2026
fe8a9f0
Document params on the factory methods
fredrbus Aug 21, 2026
aa2f0f8
Link to API-docs
fredrbus Sep 2, 2026
5b3fbfa
Handle token endpoint responses without body
fredrbus Sep 9, 2026
4c5ba68
MutualTlsTokenProvider implements Closeable
fredrbus Sep 9, 2026
9642187
Configurable timeouts for MutualTlsTokenProvider
fredrbus Sep 9, 2026
5c8820b
Fix botched markdown-links
fredrbus Sep 9, 2026
2bae4d9
Remove hash-check in RequestSignatureInterceptor
fredrbus Sep 9, 2026
2a57bfd
Mark cert-auth as legacy in docs
fredrbus Sep 9, 2026
cdabf98
Use TlsSocketStrategy, not SslConnectionFactory
fredrbus Sep 9, 2026
0cf8eb8
Close all http resources owned by the client
fredrbus Sep 10, 2026
155a3c1
Use a no-op AutoCloseable, not a nullable field
fredrbus Sep 10, 2026
8275a70
Retry one time with new access token on 401
fredrbus Sep 11, 2026
5be4699
Reseed the v19 docs from v18
fredrbus Sep 23, 2026
a7c4992
Migrate the example code to JWT/mTLS authentication
fredrbus Sep 23, 2026
37c0b29
Authenticate the Swing demo client with JWT/mTLS
fredrbus Sep 23, 2026
2a59f6b
Remove certificate authenticating factory methods
fredrbus Sep 23, 2026
34c0b94
Delete the request signing code
fredrbus Sep 23, 2026
c243e5f
Drop the unused CryptoUtil methods
fredrbus Sep 23, 2026
c68d1b4
Rename the client factory method to create
fredrbus Sep 23, 2026
61b63d9
Drop the http client factory function
fredrbus Sep 23, 2026
a1527eb
Document JWT/mTLS as the only auth method
fredrbus Sep 23, 2026
a5c07e9
Clarify the 401 retry wording in the docs
fredrbus Sep 24, 2026
6684b5b
Stop sharing the token client's SSL context with the API client
fredrbus Sep 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ licenseUrl: http://www.apache.org/licenses/LICENSE-2.0

baseurl: "/digipost-api-client-java"

currentVersion: "18.x"
versions: ["18.x", "17.x", "16.x", "15.x", "13.x", "11.x", "10.x", "9.0", "8.0"]
currentVersion: "19.x"
versions: ["19.x", "18.x", "17.x", "16.x", "15.x", "13.x", "11.x", "10.x", "9.0", "8.0"]
deprecatedVersions: ["8.0", "9.0", "10.x", "11.x", "13.x"]

collections:
Expand Down Expand Up @@ -40,6 +40,9 @@ collections:
v18_x:
output: true
permalink: /v18.x/
v19_x:
output: true
permalink: /v19.x/

# list of additional links on the right of the top menu
headerLinks:
Expand Down
1 change: 0 additions & 1 deletion docs/_v10_x/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
identifier: index
layout: default
redirect_from: /
---

<!-- Documentation -->
Expand Down
1 change: 0 additions & 1 deletion docs/_v11_x/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
identifier: index
layout: default
redirect_from: /
---

<!-- Documentation -->
Expand Down
1 change: 0 additions & 1 deletion docs/_v13_x/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
identifier: index
layout: default
redirect_from: /
---

<!-- Documentation -->
Expand Down
1 change: 0 additions & 1 deletion docs/_v15_x/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
identifier: index
layout: default
redirect_from: /
---

<!-- Documentation -->
Expand Down
1 change: 0 additions & 1 deletion docs/_v16_x/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
identifier: index
layout: default
redirect_from:
---

<!-- Documentation -->
Expand Down
1 change: 0 additions & 1 deletion docs/_v18_x/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
identifier: index
layout: default
redirect_from: /
---

<!-- Documentation -->
Expand Down
167 changes: 167 additions & 0 deletions docs/_v19_x/1_client_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
title: Instantiate and configure the client
identifier: client_config
layout: default
---

### Install

The client library is available on the [Maven Central Repository](https://central.sonatype.com/artifact/no.digipost/digipost-api-client-java).
Copy the `<dependency>`-snippet from that website and put it in your pom.xml file.
Make sure to use the latest version available.

This client requires Java 11 and `jakarta.xml-bind`.

### Configure for production use

To instantiate the client instance you need to supply your assigned _broker ID_, which
is set up to be permitted to integrate with the Digipost API. The client authenticates
with OAuth 2.0 over mutual TLS (JWT/mTLS): it obtains access tokens over an mTLS-secured
channel and sends them as bearer tokens.

Certificate-based request signing was removed in 19.0.0. If you are upgrading from 18.x,
see [Migrating from certificate-based authentication](#migrating-from-certificate-based-authentication).


#### JWT/mTLS authentication

Before you can use the Digipost API using JWT/mTLS, you must register a client with the
Digipost OAuth 2 client authority. Contact the sales team at Digipost to get access to
the client authority and register your client. More information can be found in the [Digipost API Documentation](https://digipost.github.io/digipost-technical-docs/).

Configure a `JwtAuthConfig` with your client ID and the client certificate (as a `.p12`
keystore) used for the mutual-TLS handshake against the token endpoint. The token endpoint
defaults to the production one, so it only has to be set for other environments.

```java
SenderId senderId = SenderId.of(123456);

JwtAuthConfig jwtAuthConfig;
try (InputStream sertifikatInputStream = Files.newInputStream(Paths.get("client-cert.p12"))) {
jwtAuthConfig = JwtAuthConfig
.newConfig("your-client-id")
.pkcs12KeyStore(sertifikatInputStream, "TheSecretPassword")
.build();
}

DigipostClient client = DigipostClient.create(
DigipostClientConfig.newConfiguration().build(), senderId.asBrokerId(), jwtAuthConfig);
```

This example will configure the client to communicate with the regular Digipost production
environment.

Access tokens are fetched lazily on first use and cached until shortly before they expire.
They are requested for the API given by `DigipostClientConfig.digipostApiUri`, so you do
not configure the API URI in two places.

Should the API nevertheless answer `401 Unauthorized`, the client discards the cached token,
fetches a new one and sends the request again. This is done at most once per request: if the
API rejects the new token as well, the `401` is handled like any other error response.

The access tokens are fetched with a separate HTTP client, as it has to present the client
certificate configured above in the TLS handshake against the token endpoint. Its timeouts
(and proxy, connection pool, ...) can be configured with `tokenEndpointHttpSettings(..)`:

```java
JwtAuthConfig jwtAuthConfig = JwtAuthConfig
.newConfig("your-client-id")
.pkcs12KeyStore(sertifikatInputStream, "TheSecretPassword")
.tokenEndpointHttpSettings(
HttpClientSettings.DEFAULT.timeouts(HttpClientDefaults.DEFAULT_TIMEOUTS_MS.connect(2000).connectionRequest(1000)),
HttpClientConnectionSettings.DEFAULT.socketTimeout(5000))
.build();
```

Both parameters have sensible defaults, so pass `HttpClientSettings.DEFAULT` or
`HttpClientConnectionSettings.DEFAULT` for the one you do not need to change. The timeouts of
the client talking to the Digipost API itself are configured separately, with the
`HttpClientBuilder` accepted by `DigipostClient.create(..)`.


### Custom HTTP client

The client uses Apache HttpClient 5 internally. If you need control over the underlying
HTTP client (e.g. timeouts or proxy settings), you can supply your own `HttpClientBuilder`:

```java
HttpClientBuilder clientBuilder = HttpClientFactory.createDefaultBuilder();

DigipostClient client = DigipostClient.create(
DigipostClientConfig.newConfiguration().build(), senderId.asBrokerId(), jwtAuthConfig, clientBuilder);
```


### Other environments

If you have access to other environments, this can be configured using
`DigipostClientConfig`, e.g:

```java
URI apiUri = URI.create("https://api.test.digipost.no");
DigipostClientConfig config = DigipostClientConfig.newConfiguration().digipostApiUri(apiUri).build();
```

Also point `JwtAuthConfig` at the token endpoint of that environment:

```java
JwtAuthConfig jwtAuthConfig = JwtAuthConfig
.newConfig("your-client-id")
.tokenEndpoint("https://midp.test.digipost.no/oauth2/token")
.pkcs12KeyStore(sertifikatInputStream, "TheSecretPassword")
.build();
```

#### Norsk Helsenett (NHN)

The Digipost API is accessible from both internet and Norsk Helsenett (NHN). Both entry points use
the same API, the only difference is the base URL.

```java
URI nhnApiUri = URI.create("https://api.nhn.digipost.no");
DigipostClientConfig config = DigipostClientConfig.newConfiguration().digipostApiUri(nhnApiUri).build();
```


### Migrating from certificate-based authentication

Version 19.0.0 removes certificate-based request signing. `Signer`,
`Signer.usingKeyFromPKCS12KeyStore(..)` and
`DigipostClient.withCertificateAuthentication(..)` are gone, with no deprecation period.
18.x is the last version that signs requests. `DigipostClient.withJwtMtlsAuthentication(..)`
was renamed to `DigipostClient.create(..)` at the same time, as it is now the only way to
build a client.

To migrate, register a client with the
Digipost OAuth 2 client authority to get a client ID,
and replace the `Signer` with a `JwtAuthConfig`:

```java
// Before (18.x)
Signer signer;
try (InputStream sertifikatInputStream = Files.newInputStream(Paths.get("certificate.p12"))) {
signer = Signer.usingKeyFromPKCS12KeyStore(sertifikatInputStream, "TheSecretPassword");
}

DigipostClient client = DigipostClient.withCertificateAuthentication(
DigipostClientConfig.newConfiguration().build(), senderId.asBrokerId(), signer);

// After (19.x)
JwtAuthConfig jwtAuthConfig;
try (InputStream sertifikatInputStream = Files.newInputStream(Paths.get("client-cert.p12"))) {
jwtAuthConfig = JwtAuthConfig
.newConfig("your-client-id")
.pkcs12KeyStore(sertifikatInputStream, "TheSecretPassword")
.build();
}

DigipostClient client = DigipostClient.create(
DigipostClientConfig.newConfiguration().build(), senderId.asBrokerId(), jwtAuthConfig);
```

Note that the `.p12` is generally **not** the same file. It is no longer a signing key for
your requests, but the client certificate presented in the mTLS handshake against the token
endpoint, and it is issued when you register the client.

Nothing else changes. The server still signs its responses and the client still verifies
them, so your `DigipostClientConfig`, message building and delivery code are untouched.
Loading
Loading