AuthenticateResponseType.fromJson constructor
Constructs a new instance from a JSON map.
Supports both flat format (legacy) and nested format (standard WebAuthn).
Implementation
factory AuthenticateResponseType.fromJson(Map<String, dynamic> json) {
// Check if it's the nested WebAuthn format with 'response' object
if (json.containsKey('response')) {
final response = json['response'];
if (response is! Map<String, dynamic>) {
throw FormatException(
'Expected "response" to be a Map, got ${response.runtimeType}');
}
return AuthenticateResponseType(
id: json['id'] as String? ?? '',
rawId: json['rawId'] as String? ?? '',
clientDataJSON: response['clientDataJSON'] as String? ?? '',
authenticatorData: response['authenticatorData'] as String? ?? '',
signature: response['signature'] as String? ?? '',
userHandle: (response['userHandle'] as String?) ?? '',
);
}
// Legacy flat format
return AuthenticateResponseType(
id: json['id'] as String? ?? '',
rawId: json['rawId'] as String? ?? '',
clientDataJSON: json['clientDataJSON'] as String? ?? '',
authenticatorData: json['authenticatorData'] as String? ?? '',
signature: json['signature'] as String? ?? '',
userHandle: (json['userHandle'] as String?) ?? '',
);
}