Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class RemoteJwkSet

  1. Object
  2. RemoteJwkSet

ImplementsJwkSource

The keys another server publishes at its jwks_uri, fetched when they are first needed and kept.

  • The set is kept for five minutes, then fetched again by the next request that needs it.
  • A token naming a key the set does not have makes it fetch early – that is how a rotated key is picked up – but no more than once in thirty seconds, so tokens with invented key ids cannot turn this server into a stream of requests at the issuer.
  • One request fetches at a time. The others carry on with the set they have, or fail if the first fetch has not supplied any keys yet. Failed initial fetches observe the same retry interval. No request waits for another request’s network operation.
  • When a fetch fails and there is a set, the set goes on being used and the fetch is tried again later. An issuer that is briefly unreachable does not sign everybody out.

Use an https address. The keys are what every token is trusted by, and they are only as trustworthy as the connection they came over.

Nested types

interface RemoteJwkSet.FetcherFetches the text at an address.

Fields

public static final RemoteJwkSet.Fetcher WEBThe runtime’s HTTP client, asking for JSON.

Constructors

public RemoteJwkSet(String uri)
public RemoteJwkSet(String uri, RemoteJwkSet.Fetcher fetcher)

Methods

public synchronized void setCacheSeconds(long seconds)How long a fetched set is used before it is fetched again; five minutes unless set.
public synchronized void setRefreshIntervalSeconds(long seconds)The least time between two fetches, whatever asks for them; thirty seconds unless set.
public synchronized void setClock(Clock clock)
public String getUri()
public List<Jwk> getKeys() throws IOExceptionThe keys, the one to sign with first.
public List<Jwk> refresh() throws IOExceptionThe keys, fetched again unless a fetch is in progress or the refresh interval has not elapsed.

Inherited methods

Field details

WEB

public static final RemoteJwkSet.Fetcher WEB
The runtime’s HTTP client, asking for JSON.

Constructor details

RemoteJwkSet

public RemoteJwkSet(String uri)

RemoteJwkSet

public RemoteJwkSet(String uri, RemoteJwkSet.Fetcher fetcher)

Method details

setCacheSeconds

public synchronized void setCacheSeconds(long seconds)
How long a fetched set is used before it is fetched again; five minutes unless set.

setRefreshIntervalSeconds

public synchronized void setRefreshIntervalSeconds(long seconds)
The least time between two fetches, whatever asks for them; thirty seconds unless set.

setClock

public synchronized void setClock(Clock clock)

getUri

public String getUri()

getKeys

public List<Jwk> getKeys() throws IOException
The keys, the one to sign with first.

Throws

IOException
when the keys cannot be had: a server that publishes them is not answering

refresh

public List<Jwk> refresh() throws IOException
The keys, fetched again unless a fetch is in progress or the refresh interval has not elapsed.