parseJwkSet function

List<Map<String, Object?>> parseJwkSet(
  1. String json
)

The keys of a key set given as JSON text, as /pubkey answers it ({"keys":[...]}, or that whole answer), a list of JWKs, or one JWK, for LicenseConfig.publicJwks. An object whose keys member is not a list is refused, never read as one JWK. Throws a LicenseConfigError for text that is none of these.

Implementation

List<Map<String, Object?>> parseJwkSet(String json) {
  final Object? parsed;
  try {
    parsed = jsonDecode(json);
  } on FormatException {
    throw LicenseConfigError('the key set is not JSON');
  }
  if (parsed is List) return [for (final key in parsed) _jwkOf(key)];
  final object = asObject(parsed);
  if (object == null) throw LicenseConfigError('the key set is not a JWK, a list of JWKs or a JWK set');
  if (!object.containsKey('keys')) return [object];
  final keys = object['keys'];
  if (keys is! List) throw LicenseConfigError('the key set\'s keys is not a list');
  return [for (final key in keys) _jwkOf(key)];
}