Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c416c83
Add JWT/mTLS authentication
fredrbus Jul 9, 2026
51d2c43
Rewrite RequestContentHashFilter as interceptor
fredrbus Jul 9, 2026
60c0d29
Set "request-path" attrubute in own interceptor
fredrbus Jul 9, 2026
9f2ca44
Make authentication method explicit
fredrbus Jul 24, 2026
4ebd3b0
Add docs for v19
fredrbus Jul 24, 2026
23035ed
Redirect docs root only to current version
fredrbus Jul 27, 2026
3e8b250
Fix scope structure
fredrbus Jul 28, 2026
872aa89
Derive OAuth resource from DigipostClientConfig
fredrbus Aug 14, 2026
e9d8a4c
Align examples in docs with recent changes
fredrbus Aug 14, 2026
7629686
Fail fast when signing unhashed content
fredrbus Aug 14, 2026
80329d6
DigipostClientException when token retrieval fails
fredrbus Aug 14, 2026
f143616
Clamp token cache to a positive duration
fredrbus Aug 14, 2026
09b16e3
Test MutualTlsTokenProvider with local endpoint
fredrbus Aug 21, 2026
94add03
Replace AuthMode with two factory methods
fredrbus Aug 21, 2026
1f55854
Log interceptor events under one logger
fredrbus Aug 21, 2026
3fc1380
Decouple RequestBearerTokenInterceptor from the token provider
fredrbus Aug 21, 2026
b99f529
Req.HttpReq.PathInterceptor to Req.PathInterceptor
fredrbus Aug 21, 2026
b8267da
Document params on the factory methods
fredrbus Aug 21, 2026
57dae04
Mention Nyva in docs and link to API-docs
fredrbus Sep 2, 2026
010a04b
Handle token endpoint responses without body
fredrbus Sep 9, 2026
effc05d
MutualTlsTokenProvider implements Closeable
fredrbus Sep 9, 2026
0a72b82
Configurable timeouts for MutualTlsTokenProvider
fredrbus Sep 9, 2026
79ecfda
Fix botched markdown-links
fredrbus Sep 9, 2026
19318f1
Remove hash-check in RequestSignatureInterceptor
fredrbus Sep 9, 2026
e75fbfc
Mark cert-auth as legacy in docs
fredrbus Sep 9, 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: "16.x"
versions: ["16.x", "15.x", "13.x", "11.x", "10.x", "9.0", "8.0"]
currentVersion: "19.x"
versions: ["19.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 All @@ -34,6 +34,9 @@ collections:
v16_x:
output: true
permalink: /v16.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
129 changes: 129 additions & 0 deletions docs/_v19_x/1_client_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
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. In addition, you must choose
an authentication method. The client supports two:

- **OAuth 2.0 over mutual TLS (JWT/mTLS):** the client obtains access tokens over an
mTLS-secured channel and sends them as bearer tokens. Use
`DigipostClient.withJwtMtlsAuthentication(...)`.
- **Certificate-based signing (legacy):** each request is signed with a private key. Use
`DigipostClient.withCertificateAuthentication(...)`.

The chosen method is stated explicitly in the factory method you call.
Comment thread
fredrbus marked this conversation as resolved.


#### 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 (Nyva)](https://nyva.digipost.no). 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.withJwtMtlsAuthentication(
DigipostClientConfig.newConfiguration().build(), senderId.asBrokerId(), jwtAuthConfig);
```

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.

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.withJwtMtlsAuthentication(..)`.


#### Certificate-based authentication (legacy)

Create a `Signer` instance, e.g. by using a `.p12` file to read the private key used to
sign the API requests.

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

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);
```

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

### 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();
```

When using JWT/mTLS, 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();
```


Loading
Loading