JwtPayload.fromMap constructor

JwtPayload.fromMap(
  1. Map<String, dynamic> map
)

Implementation

factory JwtPayload.fromMap(Map<String, dynamic> map) {
  var name = '';
  var subject = '';
  var username = '';
  var issuer = '';
  var audience = '';
  var nbf = DateTime.now();
  var exp = DateTime.now();
  var extra = <String, dynamic>{};

  for (var entry in map.entries) {
    switch (entry.key) {
      case 'name':
        name = entry.value;
        break;
      case 'sub':
        subject = entry.value;
        break;
      case 'username':
        username = entry.value;
        break;
      case 'iss':
        issuer = entry.value;
        break;
      case 'aud':
        audience = entry.value;
        break;
      case 'nbf':
        nbf = _getDateTime(entry.value);
        break;
      case 'exp':
        exp = _getDateTime(entry.value);
        break;
      default:
        extra[entry.key] = entry.value;
        break;
    }
  }

  var payload = JwtPayload(
    name: name,
    subject: subject,
    username: username,
    issuer: issuer,
    audience: audience,
    notBefore: nbf,
    expires: exp,
    extra: extra,
  );
  return payload;
}