buildJwsHeader function

String buildJwsHeader({
  1. required String alg,
  2. String? jku,
  3. Map<String, dynamic>? jwk,
  4. String? kid,
  5. String? x5u,
  6. List<String>? x5c,
  7. String? x5t,
  8. String? x5tS256,
  9. String? typ,
  10. Map<String, dynamic>? extra,
})

Implementation

String buildJwsHeader(
    {required String alg,
    String? jku,
    Map<String, dynamic>? jwk,
    String? kid,
    String? x5u,
    List<String>? x5c,
    String? x5t,
    String? x5tS256,
    String? typ,
    Map<String, dynamic>? extra}) {
  Map<String, dynamic> jsonObject = {};

  jsonObject.putIfAbsent('alg', () => alg);

  if (jku != null) {
    jsonObject.putIfAbsent('jku', () => jku);
  }

  if (jwk != null) {
    jsonObject.putIfAbsent('jwk', () => jwk);
  }

  if (kid != null) {
    jsonObject.putIfAbsent('kid', () => kid);
  }

  if (x5u != null) {
    jsonObject.putIfAbsent('x5u', () => x5u);
  }

  if (x5c != null) {
    jsonObject.putIfAbsent('x5c', () => x5c);
  }

  if (x5t != null) {
    jsonObject.putIfAbsent('x5t', () => x5t);
  }

  if (x5tS256 != null) {
    jsonObject.putIfAbsent('x5t#S256', () => x5tS256);
  }

  if (typ != null) {
    jsonObject.putIfAbsent('typ', () => typ);
  }

  if (extra != null) {
    jsonObject.addAll(extra);
    var keyList = extra.keys.toList();
    jsonObject.putIfAbsent('crit', () => keyList);
  }

  var jsonString = jsonEncode(jsonObject);
  return base64UrlEncode(utf8.encode(jsonString));
}