RegisterRequestType.fromJson constructor

RegisterRequestType.fromJson(
  1. Map<String, dynamic> json
)

Constructs a new instance from a JSON map.

Implementation

factory RegisterRequestType.fromJson(Map<String, dynamic> json) {
  final excludeCredentials = json['excludeCredentials'] as List<dynamic>?;
  final rp = json['rp'];
  final user = json['user'];
  final authenticatorSelection = json['authenticatorSelection'];
  final pubKeyCredParams = json['pubKeyCredParams'] as List<dynamic>?;

  if (rp is! Map<String, dynamic>) {
    throw FormatException('Expected "rp" to be a Map, got ${rp.runtimeType}');
  }
  if (user is! Map<String, dynamic>) {
    throw FormatException(
        'Expected "user" to be a Map, got ${user.runtimeType}');
  }

  return RegisterRequestType(
    challenge: json['challenge'] as String? ?? '',
    relyingParty: RelyingPartyType.fromJson(rp),
    user: UserType.fromJson(user),
    excludeCredentials: excludeCredentials != null
        ? excludeCredentials
            .whereType<Map<String, dynamic>>()
            .map((e) => CredentialType.fromJson(e))
            .toList()
        : [],
    authSelectionType: authenticatorSelection is Map<String, dynamic>
        ? AuthenticatorSelectionType.fromJson(authenticatorSelection)
        : null,
    pubKeyCredParams: pubKeyCredParams != null
        ? pubKeyCredParams
            .whereType<Map<String, dynamic>>()
            .map((e) => PubKeyCredParamType.fromJson(e))
            .toList()
        : null,
    timeout: json['timeout'] as int?,
    attestation: json['attestation'] as String?,
  );
}